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

[eluser]tarciozemel[/eluser]
OK, so I not understood very well... Let's some example. I want a 1:N relationship according this:

user_model.php
Code:
var $has_one = array(
    'user_group' => array(
        'class' => 'user_group_model'
    )
);


user_group_model.php
Code:
// In the "group" table, I have only the "id", "name" and "desc" colums
var $has_many = array(
    'user' => array(
        'class' => 'user_model'
        'join_self_as' => 'group' // In the "user" table, exists a "group_id" colum
    )
);

When I try do this:

Code:
$user = new User_model();
$user->where('login', 'foobar')->get();
$user->user_group->get();
echo $user->user_group->desc;

I give this error:

Quote:DataMapper Error: 'User_model' is not a valid parent relationship for User_group_model. Are your relationships configured correctly?

So, where's my mistake? I have to specify a "join_self_as" in the user_model even the other table not having a relationship field? If yes, how?

Regards!


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