多的has_many:通过 [英] Multiple has_many :through

查看:127
本文介绍了多的has_many:通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对象模型中,我有

has_many :likes
has_many :hates
has_many :users, :through => :likes
has_many :users, :through => :hates

如何获得用户的喜好名单?例如。 object.users< ---但我怎么喜​​欢通过指定或不喜欢

How do I get the list of users for likes? E.g. object.users <--- but how do I specify through likes or hates?

推荐答案

您需要给这两个不同的协会不同的名字。怎么样

You need to give these two different associations different names. What about

has_many :likes
has_many :hates
has_many :likers, :through => :likes, :source => :user
has_many :haters, :through => :hates, :source => :user

这篇关于多的has_many:通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆