我正在搜索与一组标签匹配的用户。我想返回匹配的标签及其链接的配置文件。我可以通过链接标签获取用户,但不能获取配置文件。我尝试将:profile添加到:include,但这不起作用。我已经尝试将:profile放在:join中,它可以工作但只返回第一行。
有什么建议吗?
# Returns only one record instead of the four it should
User.find(:all, :joins => :profile, :include => :skills, :conditions => { :tags => { :id => search_tags } } )
# Returns all four records that match but not their profiles
User.find(:all, :include => [:skills, :profile], :conditions => { :tags => { :id => search_tags } } )
更新 事实证明,我的数据播种机没有为所有用户播种Facebook数据。所以第二个发现实际上有效
答案 0 :(得分:1)
请试试这个
User.where(:tags => { :id => search_tags }).includes([:skills, :profile])
答案 1 :(得分:0)
如果您的模型已链接,则无需使用find方法获取配置文件。获得用户后,您可以随时拨打@user.profile