sf1.4/propel中的一对一关系 [英] Relation one to one in sf1.4/propel

查看:50
本文介绍了sf1.4/propel中的一对一关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

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

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

它不起作用.它说:

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

Call to undefined method BasesfGuardUser::getSfGuardUserProfile

SF 1.4/推进 1.4

sf 1.4/propel 1.4

哈维尔

推荐答案

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

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)

由于您的 sfGuardUserProfile 与您的 sfGuardUser 是一对多关系,因此 getSfGuardUserProfile() 方法不存在,确实存在的方法是 sfGuardUserProfiles()(唯一的区别是方法中的s"名称,它将产生一个用户配置文件数组)

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:抱歉我的英语不好:D

ps: sorry for my bad english :D

这篇关于sf1.4/propel中的一对一关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆