Welcome Guest, Not a member yet? Register   Sign In
In-Table Foreign Keys in DataMapper ORM
#9

[eluser]tarciozemel[/eluser]
With the help of my pal, I did this works! I had to use “join_self_as” in user model even that not have an FK in the other table. So, the solution is:

user_model.php (class User_model)
Code:
var $has_one = array(
    'user_group' => array(
        'class' => 'user_group_model',
        'other_field' => 'user',
        'join_other_as' => 'group',
        'join_self_as' => 'user'
    )
);


user_group_model.php (class User_group_model)
Code:
var $has_many = array(
    'user' => array(
        'class' => 'user_model',
        'other_field' => 'user_group',
        'join_other_as' => 'user',
        'join_self_as' => 'group'
    )
);

I think DataMapper documentation should have more examples, especially in the "Advanced Relationships" section. This would greatly will help people! :-D

Very thank you for you help and congratulations for the DataMapper!


Messages In This Thread
In-Table Foreign Keys in DataMapper ORM - by El Forum - 05-28-2011, 01:19 PM
In-Table Foreign Keys in DataMapper ORM - by El Forum - 05-29-2011, 02:35 PM
In-Table Foreign Keys in DataMapper ORM - by El Forum - 05-29-2011, 03:12 PM
In-Table Foreign Keys in DataMapper ORM - by El Forum - 05-30-2011, 01:10 AM
In-Table Foreign Keys in DataMapper ORM - by El Forum - 08-03-2011, 09:15 AM
In-Table Foreign Keys in DataMapper ORM - by El Forum - 08-03-2011, 09:29 AM
In-Table Foreign Keys in DataMapper ORM - by El Forum - 08-03-2011, 11:35 AM
In-Table Foreign Keys in DataMapper ORM - by El Forum - 08-03-2011, 12:46 PM
In-Table Foreign Keys in DataMapper ORM - by El Forum - 08-04-2011, 11:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB