Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个表用户和一个表组。每个组都有一个 GroupLeader。所以我使用的字段是 groupLeader ($hasOne),其中包含用户的外键。
我无法得到那种关系。所以我的问题是,如何在具有不同名称的字段上定义关系。
谢谢你的提示。远藤
你的模型应该看起来:
class Group extends AppModel { public $name = 'Group'; public $belongsTo = array('GroupLeader' => array( 'className' => 'User', 'foreignKey' => 'groupLeader' ) ); }
试试上面的代码。并询问它是否不适合您。