sf1.4/propel 中一对一的关系
我已经安装了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
sfGuardProfile 中的 user_id 字段应该是主键,因此 propel 会将其视为一对一关系。
由于您的 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.
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