用户选择一些专业知识并按预期保存,对于配置文件相同,配置文件选择一些专业知识,所有都按预期保存。我可以找到与专业知识相关的配置文件。
用户模型:
has_and_belongs_to_many :expertises
专业知识模型:
has_and_belongs_to_many :profiles
has_and_belongs_to_many :users
现在,让我们说用户选择一些专业知识,我想显示具有相同专业知识的所有配置文件?关于如何做到这一点的任何想法?
这可以在控制器中完成,还是需要创建另一个连接表?
答案 0 :(得分:1)
用户has_many :matching_profiles, :through => :expertises, class_name => "Profile", :source => :profiles
然后您可以@user.matching_profiles
查找具有匹配专业知识的所有配置文件
您还必须拥有
专业知识课程中的 has_many :profiles, :through => :expertise_profiles, :source => :profile
和has_many :expertises, :through => :user_expertises, :source => :expertise