1

我得到一个 metawhere 连接依赖错误,内容如下:

@companies_user = Company.joins(:contact).where(:contact => {:user_id => current_user.id}).uniq

公司有_很多联系人

换句话说,每个联系人都有一个方法 company_id

我想向那些公司(只有一家)展示联系人的 user_id 等于进行搜索的用户的 user_id。

4

2 回答 2

0

为什么不这样做呢?

current_user.contact.companies

然后你可以使用 .limit 只获取一个......

于 2011-10-22T09:47:03.063 回答
0

好吧,如果您的公司有很多联系人,那么您应该不contacts包括contact

@companies_user = Company.joins(:contacts).where(:contacts => {:user_id => current_user.id}).uniq
于 2011-10-22T15:47:00.677 回答