[英]Yii find all relation of a model
I'm dealing with Yii framework and I have a little question about find. 我正在与Yii框架打交道,我对find有一个小问题。 This is my situation:
这是我的情况:
I have a model user and a relation user->friends. 我有一个模型用户和一个关系用户->朋友。 So, to get all the friends, I just need to do $userModel->friends.
因此,要获得所有朋友,我只需要做$ userModel-> friends。 And this will return an array containing all the user model that are his friends.
这将返回一个包含所有用户模型的数组,这些用户模型是他的朋友。 Now, what I want to do, is, given a list of user, loop over it, for each user check if this user is a friend.
现在,我想要做的是,在给定用户列表的情况下,遍历该列表,为每个用户检查该用户是否是朋友。 I know I can user User::model()->exists, but how?
我知道我可以使用User :: model()->存在,但是如何? I'm a bit lost here.
我在这里迷路了。
Thank you 谢谢
Why not to put your relations()
code here? 为什么不将您的
relations()
代码放在这里? If friends
relation itself has defined options by which another User is a friend, you do not need to check this again. 如果
friends
关系本身定义由其他用户是朋友选择,你不需要再次进行检查。 Just traverse friends 只是遍历朋友
foreach ( $userModel->friends as $friend ) {
var_dump( $friend );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.