Has one的一个问题

hi,qiang哥

我遇到一个问题,我想让user表中的profileid字段和profile表中的id字段关联


可是我如何关联都没有在yii的logs中看到查询profile的sql,我的设置如下

user model :

public function relations()


{


	return array(


		'profile'=>array(self::HAS_ONE, 'profile', 'profileid'),


	);


}





 请问强哥这个关联是否必须在profile表中设置外键?


 或者还有其他地方需要设置,谢谢

你是怎么查询只用profile的?

楼主搞错了吧,按你表的设计,两表关系应该是User belongsTo Profile。

但看你的代码,又是User hasOne Profile。

所以应该是在Profile里建立一个userId字段,去关联User




public function relations()

{

return array(

'profile'=>array(self::HAS_ONE, 'profile', userId),

);

}




记得userId带上引号^_^