Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorgizmo
     

    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?

    • CommentAuthorreeceer
     
    If I'm understanding you correctly did you try this on your UserInfo class

    var $belongsTo = array ('customer' => array('primary_key_name' => 'USER_PK'));
    • CommentAuthorgizmo
     

    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.

    • CommentAuthorKaste
     

    is this solved? Can you use primary_key === foreign_key?

    • CommentAuthorgizmo
     

    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.