I have two models connected as follows:
class User extends ActiveRecord
{
var $has_one = array ('user_info' => array ('foreign_key' => 'USER_PK','dependent' => true)
);
}
class UserInfo extends ActiveRecord {
var $belongsTo = array ('customer');
}
When i create a new User, a new User_info object is automagically created; my problem is that the primary key for UserInfo is the same field ('USER_PK') used as foreign key in the relation, and is setted to 0 and not as expected. I've tried adding a different primary key for User_info, and everything works (unfortunately i can't do this in production environment). What am i doing wrong? Beside this: is there a way for preventing the framework to automatically save associated objects when creating a new object?
Hi receer, thanks for your reply. In fact I mistype my UserInfo class, which is defined as follow
class UserInfo extends ActiveRecord { var $belongsTo = array ('user_info'); }
Sorry! :-) By the way: the first thing I've tried to make things work was setting primary_key_name as you suggested, but nothing changed. It seems that having primary_key === foreign_key in has_one relations leads to problems.
is this solved? Can you use primary_key === foreign_key?
Actually not. I've temporarily added a separate id field to solve the problem; i'm going to take an in-deep analysis this weekend.
1 to 5 of 5