开发者

Relation one to one in sf1.4/propel

开发者 https://www.devze.com 2023-02-05 06:51 出处:网络
i have installed sfGuardPlugin and created this model: propel: sf_guard_user_profile: _attributes:{ phpName: sfGuardUserProfile }

i have installed sfGuardPlugin and created this model:

propel:
  sf_guard_user_profile:
    _attributes:       { phpName: sfGuardUserProfile }
    id:                ~
    user_id:           { type: integer, foreignTable: sf_guard_user, foreignReference: id, required: true, onDelete: cascade }
    name:              varchar(50)

As it is written here, http://www.propelorm.org/wiki/Documentation/1.4/Relationships (see "One-to-one relationships"), It is supposed symfony generates the function sfGuardUser->getSfGuardUserProfile() and sfGuardUserProfile->getSfGuardUser() but I have this code:

  // this works
  $c1 =  new Criteria();  
  $elements = sfGuardUserProfilePeer::doSelect($c1);
  var_dump($elements[0]->getSfGuardUser());

  // this doesn't work
  $c2 = new Criteria();
  $elements = sfGuardUserPeer::doSelect($c2);
  var_dump($elements[0]->getSfGuardUserProfile());

and it doesn't work. I开发者_运维百科t says:

Call to undefined method BasesfGuardUser::getSfGuardUserProfile

sf 1.4/propel 1.4

Javier


the user_id field in the sfGuardProfile should be a primary key, so propel will see it as a one-to-one relation.

propel:
  sf_guard_user_profile:
    _attributes:       { phpName: sfGuardUserProfile }
    user_id:           { type: integer, foreignTable: sf_guard_user, foreignReference: id, required: true, onDelete: cascade, primary: true }
    name:              varchar(50)

as your sfGuardUserProfile is a one-to-many relation with your sfGuardUser, so the getSfGuardUserProfile() method doesn't exist, the method that does exist is sfGuardUserProfiles() (the only difference is an 's' in the method name, and it will result an array of user profile)

ps: sorry for my bad english :D

0

精彩评论

暂无评论...
验证码 换一张
取 消