Welcome Guest, Not a member yet? Register   Sign In
DataMapper 1.6.0

[eluser]Spir[/eluser]
I had weird issue using Datamapper. If I do this :
Code:
$myObject->where('id', $id)->get();
I have not the same result as :
Code:
$myObject->get_by_id($id)->get();

Using the get_by_id method I have all the object even if ID exists. Using the where method I have the object I requested.

Any idea? I didn't take a closer look to those method within the lib yet.

[eluser]NachoF[/eluser]
When are people gonna understand that thing is not supported anymore?? the developer has been lost for years.... and new version of dmz datamapper was just released a couple of days ago and people still are stubborn enough to use this old thing.....

@Spir,
it should just be
$myObject->get_by_id($id);

but please switch to dmz.... what happened was that the creator of datamapper stopped working on it so Overzealous took over.. he decided to make it clear that it was his version by changing the name and now people think they are two different projects when in fact its just the new version of the same project (basically).

[eluser]Spir[/eluser]
Yes actually I started using ORM in COdeIgniter this week with Datamapper. I saw DMZ was Datamapper upgraded and updated with new features and that to move from DM to DMZ is quite easy so I'll make the move for sure.

I see my mistake. Thanks.

By the way I was wondering what was better (I see DMZ use foreign key) : foreign key or new table with both key and an auto increment key when doing a relation.

I always have done foreign keys when 1..n and a third table when n..n
"Fifth normal form" looks old fashion style. Or am I wrong?

[eluser]OverZealous[/eluser]
@Spir
You are calling get() twice. If you look at the generated queries using CodeIgniter's output profiler, you would see this.

get-by_id DOES the get for you. That's the point. :-)

Edit:
Oops, the responses wrapped to the next page. I see it's been answered already.

[eluser]GregX999[/eluser]
Forgive me if this has been answered already (the thread is SO long)...

How do you name model classes, model file names and database tables when the name has multiple words? For example, "Press Item". Do all three need to be named the same? Is one model class "PressItem" and db table "press_item"? And filename "press_item.php" or "pressitem.php"? The docs don't mention how that works.

Thanks,
Greg

[eluser]OverZealous[/eluser]
@GregX999

File names, models, and database tables have to have the same name. They only differ in case (and pluralization for database tables). Naming is explained in DataMapper Models.

They must be valid PHP class names, which means no spaces, only alphanumerics and an underscore, and must start with a letter. (While databases allow table names with spaces, I highly recommend against that in general practice; DMZ does not allow it at all.)

The name of the table must simply be the lowercase pluralized form of the class name. Therefore PressItem becomes pressitems, while Press_Item becomes press_items. The filename is simply the lowercase form of the class name: pressitem.php or press_item.php, respectively.

(Technically, the classname should only have the first letter capitalized, but PHP is case-insensitive for class names, so don't worry about that.)

How you choose name multi-word items is up to you. I recommend using CamelCase and no underscores, as it makes debugging complex queries easier, since DMZ uses underscores to separate components when naming join tables and querying related tables.

Edit:
I forgot to mention that the name of relationships to the item, unless specifically set, is the lowercase form of the class name (pressitem or press_item). IE:
Code:
$foo = new Foo();
$foo->pressitem->get();

[eluser]OverZealous[/eluser]
DOH

I just realized which board I was on.

The above information should still be mostly correct, except the manual link takes you to DMZ's manual, not DataMapper's, and you cannot specifically name the relationship.

Sorry if there was any confusion.

[eluser]GregX999[/eluser]
Thanks, that's perfect! I didn't see there was a separate DMZ thread - I AM using the DMZ version.

[eluser]patie[/eluser]
datamapper is a cool thing! ... but the model (in MVC) has lost importance for me, most of the database command in the controller I have now is this normal? Smile

[eluser]cladff[/eluser]
Hi,

I have an issue with datamapper and 1and1.
In fact all works fine but when i try to make a where or other query _related it doesn't make link in query.

in exemple

Code:
$arr_u=array();
$u=new User()
$u->where('activated',1)->get()
foreach($u->all as $user)
   $arr_u[]=$u->id;

$p=new Project();
$p->where_in_related($u,'id',$arr_u)->where('session','2010-01')->get();

on my developpment server it works fine but on 1and1 it doesn't make anything about link between user and project in the query.


if you have an idea? i correct it for the moment with a hand crafted full query but i wanted to use datamapper fully...

Thanks in advance

Ps: Sorry about my english if there is mistakes.




Theme © iAndrew 2016 - Forum software by © MyBB