Relation one to one in sf1.4/propel

拟墨画扇 提交于 2019-12-11 19:05:09

问题


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. It says:

Call to undefined method BasesfGuardUser::getSfGuardUserProfile

sf 1.4/propel 1.4

Javier


回答1:


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



来源:https://stackoverflow.com/questions/4715164/relation-one-to-one-in-sf1-4-propel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!