datamapper two relations to same model |
[eluser]TomMRiddle[/eluser]
we have a to and from user relations on a recommendation table. we dont know how to write this in datamapper(DMZ). How do we write the relationship in the models for both the User model and the recommendation model? We have made what we think is right in the recommendation model, but don't know for sure, and we are completely lost about how to write it all in the user model. in recommendation model: Code: $has_one = array( An example on how to access the relation from either end would be much appreciated too thankful for your help
[eluser]WanWizard[/eluser]
Check the manual: http://datamapper.wanwizard.eu/pages/adv...tions.html, "Multiple Relationships to the Same Model".
[eluser]TomMRiddle[/eluser]
We spent hours on this, can't believe we missed it when it was right in there... So I guess this is how we should do it: Code: class User extends DataMapper { and then We access them like this: Code: $r = new Recommendation($id); The corresponding database tables: users: id - INT primary recommendations: from_user_id - INT FK users id to_user_id - INT FK users id Correct? ... I guess we will find out ourself when we try it tomorrow. tnx for the help
[eluser]WanWizard[/eluser]
Correct. Note that the ITFK's in Recommendation would be 'from_user_id' and 'to_user_id' (i.e. the custom model name, followed by '_id'). |
Welcome Guest, Not a member yet? Register Sign In |