无法引用 Yii 的 ActiveRecord 中的相关表
我试图在 Yii 中获取相关表,但在尝试引用 event.text 字段时它一直给我一个错误。
return new CActiveDataProvider( 'InvitationCode', array(
'criteria'=>array(
'select' => array( 't.id', 'code', 'Event.text' ),
'condition'=>'t.id >= :min_code_id AND t.id <= :max_code_id',
'order'=>'t.id Asc',
'with' => array( 'Event' ),
'params' => array(
':min_code_id' => $min_code_id,
':max_code_id' => $max_code_id,
),
),
));
通过关系“Event”与 InvitationCode 相关的表事件确实有一个文本字段,但我无法使用“event.text”或“Event.text”访问它
如果我保留“选择”部分,它只会带来 InvitationCode 的字段,而不会带来相关表事件中的任何字段,尽管它位于“with”部分中。
如何引用相关表Event?
I'm trying to get a related table in Yii and it keeps giving me an error trying to reference the event.text field.
return new CActiveDataProvider( 'InvitationCode', array(
'criteria'=>array(
'select' => array( 't.id', 'code', 'Event.text' ),
'condition'=>'t.id >= :min_code_id AND t.id <= :max_code_id',
'order'=>'t.id Asc',
'with' => array( 'Event' ),
'params' => array(
':min_code_id' => $min_code_id,
':max_code_id' => $max_code_id,
),
),
));
The table event which is related to InvitationCode through the relation 'Event' does have a text field, but I can't access it with either 'event.text' nor 'Event.text'
If I leave the 'select' part out, it only brings the fileds of InvitationCode and none of the fields from the related table Event despite it's in the 'with' part.
How can I reference the related table Event?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确切的错误消息是什么?
您可以发布 InvitationCode 模型类中定义关系()的代码吗?
您是否启用了查询日志记录以查看生成的确切查询?
正如评论所指出的,您可能必须显式设置 Together=>true 才能进行急切加载。
来自: http://www.yiiframework.com/doc/guide/1.1 /en/database.arr
What is the exact error message?
Can you post the code defining relations() in InvitationCode model class?
Did you enable query logging to see the exact query generated?
As the comment noted, you probably have to explicitly set together=>true for eager loading.
From: http://www.yiiframework.com/doc/guide/1.1/en/database.arr