sf1.4/propel 中一对一的关系

发布于 2024-10-12 03:48:00 字数 1111 浏览 3 评论 0原文

我已经安装了 sfGuardPlugin 并创建了此模型:

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)

正如此处所写,http://www. propelorm.org/wiki/Documentation/1.4/Relationships(参见“一对一关系”),假设 symfony 生成函数 sfGuardUser->getSfGuardUserProfile() 和 < code>sfGuardUserProfile->getSfGuardUser() 但我有这个代码:

  // 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());

它不起作用。它说:

调用未定义的方法 BasesfGuardUser::getSfGuardUserProfile

sf 1.4/propel 1.4

哈维尔

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自我难过 2024-10-19 03:48:00

sfGuardProfile 中的 user_id 字段应该是主键,因此 propel 会将其视为一对一关系。

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)

由于您的 sfGuardUserProfile 与 sfGuardUser 是一对多关系,因此 getSfGuardUserProfile() 方法不存在,存在的方法是 sfGuardUserProfiles() (唯一的区别是方法名称中的“s”,并且它会产生一系列用户配置文件)

ps:抱歉我的英语不好:D

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文