DMZ confusion |
[eluser]Lyon[/eluser]
[quote author="WanWizard" date="1279884473"]You have defined a one-to-many between user and post, on the user field author. What happens is that your 'get_by_username' gets the user record. When you then requests the post, DMZ knows from your definition that the posts table has a field called 'author' which is the foreign key to users. It basically does a "SELECT * FROM posts WHERE author = <userid>". You can do Code: $u->check_last_query(); Thanks :-) You've helped me trace down the problem of why it didn't look right, it wasn't lol. It would work by getting the posts from a user, but no the user from a post. The solution was : In user : Code: var $has_many = array( Code: var $has_one = array( I understand it now. The first array contains the property you use to access the data from the relationship: e.g. $post->author or $user->posts The class is literally the class that the other_field belongs to. e.g. the author field can be found in class post in the has_one or has_many array or the posts reference can be found in the user class. The rules for mapping from the class to the database take care of the rest. Thanks a lot for your help WanWizard, that check last query will save me a ton of hassle, I honestly would never have thought to look in the 'Utility Methods' section of the documentation lol. Thanks again! Edit : If anyone comes across this thread just to let you know if you use : Code: echo $u->check_last_query(); More information can be found here. |
Messages In This Thread |
DMZ confusion - by El Forum - 07-22-2010, 05:55 PM
DMZ confusion - by El Forum - 07-23-2010, 12:27 AM
DMZ confusion - by El Forum - 07-23-2010, 01:37 AM
|