I am working with some many to many relationships and have my relationships defined as the following:
class Users_model extends DataMapper
{
public $table = "users";
public $has_many = array(
'profile_fields' => array(
'class' => 'profile_fields_model',
'other_field' => 'users',
'join_self_as' => 'user',
'join_other_as' => 'profile_field',
'join_table' => 'users_profile_fields',
),
);
}
class Profile_fields_model extends DataMapper
{
public $table = "profile_fields";
public $has_many = array(
'users' => array(
'class' => 'users_model',
'other_field' => 'profile_fields',
'join_self_as' => 'profile_field',
'join_other_as' => 'user',
'join_table' => 'users_profile_fields',
),
);
}When I execute the command
$User->save($Profile_field);I get the error “Unable to relate users_model with profile_fields_model.”
I started to dig a little deeper and realized that DatamMapper (line 5041 and 5492) is trying to look up the relationship by the model name “profile_fields_model” instead of looking at the other_field parameter “profile_fields”.
I was able to get around this by using the following code:
$User->save($Profile_field, 'profile_fields');But now I am stuck trying to find a work around using set_join_fields()