Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition)
#31

[eluser]NachoF[/eluser]
I have to say datamapper and dmz really are great.... they should be built in into CI so that peole can create other plugins based on it..... I got into this discussion at the iScaffold thread cause I figured it makes no sense that if I want to use their CRUD app I cant because their queries will be based on a different kind of model than the Datamapper model... if CI was more standardized then I wouldnt have to make the decision between using Datamapper and using iScaffold, which is stupid.
#32

[eluser]OverZealous[/eluser]
I appreciate the compliment!

I doubt very much that something like DataMapper would ever get included in the core of CodeIgniter. It has a pretty heavy overhead if it isn't something you want to use (e.g.: loading all of your models into memory).

CodeIgniter has a fairly well rounded extension mechanism, though. The openness of the mechanism is what allows something like CodeIgniter, or the other ORM toolkits, to be built. If they declared a specific model, or specific library, format, it would significantly limit the ability to write something like DM.

It seems to me that it would be very easy to write scaffolding code that works on top of DataMapper/DMZ. It has a very simple structure, and all of the fields are declared directly (either through $validation or through the $fields array). For my code, I added a 'type' element to my $validation arrays. This, along with a custom class that gets loaded as needed, allows me to generate both editing fields and render dates, numbers, currency, and multi-line text very easily.

However, scaffolds in general are a quick way to show data, but they almost always fail under any sort of real work. By the time they offer enough customization to be truly useful (conditionals, adding security checks, adjusting layout), they have practically duplicated using basic PHP templates!
#33

[eluser]NachoF[/eluser]
[quote author="OverZealous.com" date="1241576229"]I appreciate the compliment!

I doubt very much that something like DataMapper would ever get included in the core of CodeIgniter. It has a pretty heavy overhead if it isn't something you want to use (e.g.: loading all of your models into memory).

CodeIgniter has a fairly well rounded extension mechanism, though. The openness of the mechanism is what allows something like CodeIgniter, or the other ORM toolkits, to be built. If they declared a specific model, or specific library, format, it would significantly limit the ability to write something like DM.
[/quote]

Im not sure what you mean by pretty heavy overhead...other frameworks (like rails) have the features that come with datamapper/dmz built in
#34

[eluser]OverZealous[/eluser]
@NachoF
And I wouldn't use RoR for real applications, either. Tongue That's partly what drew me to CodeIgniter. (That, and, while I've always been a Java developer, web development in Java has just gotten too complicated for its own good. Duplicating all your declarations in XML = Sick )

My point is that not everyone wants an ORM, and CodeIgniter's optional ActiveRecord already handles a lot of what RoR makes so special.

I just think its good to keep the core of CI lightweight, and customizable for the developer. As it is I have to spend a lot of time "fixing" updates to CodeIgniter (they have a bad tendency to over-simplify use cases in the ActiveRecord class, breaking any remotely complicated queries). It's like the MySQL `table`.`*` error — the CI developers decided they wanted to protect identifiers, without thinking about the fact that there is a whole class of non-identifier SQL elements, such as functions (coalesce(), for example, is something I use a lot), or that commas can appear inside function values!.

But enough sidetracking on this thread... ;-)
#35

[eluser]NachoF[/eluser]
What would be the proper way of getting this done??
say you have products and receipts, N to N relationship so I have to use a separate table called products_receipts

and I have a product $p and a receipt $r, how would I check if those two are related in the join table??
Im thinking of
Code:
if(exists($r->product->get_by_id($p->id)))
{
//do something
}
But im not sure if there is a way to get a true false response without having to access the attributes and just use the objects themselves.. kind of like a $r->is_related($p) that would give me true or false... any recommendations?
#36

[eluser]OverZealous[/eluser]
You almost had it:
Code:
if($r->product->get_by_id($p->id)->exists()) {
...

The exists() function — which just checks to see if $object->id is not empty() — was designed for that purpose. It is part of the core DataMapper.

Quote:But im not sure if there is a way to get a true false response without having to access the attributes and just use the objects themselves..
Also, I'm not sure what you meant by that.

Otherwise, there is no method within DM that is specifically designed to see if two objects are related.
#37

[eluser]NachoF[/eluser]
[quote author="OverZealous.com" date="1241598736"]You almost had it:
Code:
if($r->product->get_by_id($p->id)->exists()) {
...

The exists() function — which just checks to see if $object->id is not empty() — was designed for that purpose. It is part of the core DataMapper.

Quote:But im not sure if there is a way to get a true false response without having to access the attributes and just use the objects themselves..
Also, I'm not sure what you meant by that.

Otherwise, there is no method within DM that is specifically designed to see if two objects are related.[/quote]

Yeah, I noticed I got it wrong and fixed it already, thank you... and you got my question right, I was asking if there was a method that checked if two objects where related, but it doesnt matter, this works ok... I have a problem still though.. why is it that in some cases datamapper assumes it has to update instead of insert... whats the logic behind it??.. for some reason its trying to update an entry whereas I just want to insert it for the first time.... this is whats happening
Code:
$session=new Session();
$session->get_by_id("somestring");
if(!$session->exists())
{
$session->id="thesamestringasbefore"
$session->save();
}
when the exists returns false it tries to update instead of create.
#38

[eluser]OverZealous[/eluser]
I'm pretty sure DataMapper only works with numerical ids. It is designed specifically to work with automatically generated ids (e.g.: SERIAL or AUTONUM)

DataMapper inserts if the object has an empty id, and updates if it is not empty. There is no way to insert a row with a specific id, and there is no way to update a row with an empty id (0 or '', for example).

In your case, use autonums for the id, and store the session id in a different column.
#39

[eluser]Thorpe Obazee[/eluser]
accession05313. lol
#40

[eluser]NachoF[/eluser]
[quote author="OverZealous.com" date="1241600018"]I'm pretty sure DataMapper only works with numerical ids. It is designed specifically to work with automatically generated ids (e.g.: SERIAL or AUTONUM)

DataMapper inserts if the object has an empty id, and updates if it is not empty. There is no way to insert a row with a specific id, and there is no way to update a row with an empty id (0 or '', for example).

In your case, use autonums for the id, and store the session id in a different column.[/quote]
Ok, that worked.. thanks.




Theme © iAndrew 2016 - Forum software by © MyBB