gpt4 book ai didi

yii - 在 YIi 中建立关系时的条件

转载 作者:行者123 更新时间:2023-12-04 03:31:36 26 4
gpt4 key购买 nike

代理人:
agent_id (primary key)
用户:

f_id (foreign key)
type

我以这种方式创建了关系
public function relations() {
return array(
'user' => array(self::HAS_ONE, 'Users', 'f_id'),
);
}

但是我想添加更多条件,例如仅在 type=3 时才加入在用户表中。

谢谢。

最佳答案

如果您使用此命令,则不会出现“未定义属性“CHasOneRelation.0”之类的错误:

public function relations()
{
return array(
'user' => array(
self::HAS_ONE,
'Users',
'f_id',
'on' => 'user.ref_type = :type',
'params' => array(':type' => 3))
);
}

请参阅此链接: http://www.yiiframework.com/forum/index.php/topic/10185-using-relations-and-conditions/

关于yii - 在 YIi 中建立关系时的条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10891294/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com