Welcome Guest, Not a member yet? Register   Sign In
Trouble with datamapper
#1

[eluser]richzilla[/eluser]
Hi all, im in the process of trying to figure out datamapper, since it looks to be a much cleaner way of doing things than using standard models. However, im havign a little trouble getting my head around some of the more complex relationships. The one i think im stuck with is having multiple relationships to the same model. Ive been through the user guide and it doesnt seem to be sinking in. The situation i have:

A table of users

Code:
id
username
password
etc...

and a table of posts

Code:
id
created_by
edited_by
etc...

obviously created by and edited by are both users. At present i understand it my post model would contain

Code:
$hasOne = array(
    'created_by' => array (
    'class' => 'user',
    'other_field' => 'id'
),
    'edited_by' => array (
    'class' => 'user',
    'other_field' => 'id'
)
);

because i would expect those fields to contain an id from the users table. However i cant understand a). wether ive got this right in the first place. and b). what i put in my users model to tie into this. Any help from you guys would be greatly appreciated.

Thanks
#2

[eluser]OverZealous[/eluser]
I don't know if you are still looking for a response to this (I don't usually search the forums for questions regarding DMZ), but your property is incorrectly named in your example ($hasOne is incorrect, it should be $has_one).
#3

[eluser]richzilla[/eluser]
Hi thanks for the reply, i should have spotted that one really.... That wasnt the problem i was having, the problem is i cant get my head around having multiple relations on the same model. Once again, any help would be hugely appreciated.
#4

[eluser]OverZealous[/eluser]
OK, well, looking again, your sample still looks nothing like the examples provided in the docs and example application. There are examples in the docs for the exact situation you are describing. The relationship is described for both objects. At the least you can start by copying that code correctly.

There's also a completely functional example of this relationship structure in the example application. Just look under zip/examples at the User and Bug models.

Other Problems in your example:
• 'other_field' should be the column name without the _id column. Just like $has-one normally relates.
• Your related column names (on the table) have to end with _id.




Theme © iAndrew 2016 - Forum software by © MyBB