我的模型(只是一个插图)
Movie
has_many :usermovies
Usermovie
belongs_to :user
belongs_to :movie
User
has_many :usermovies
现在在compare
行动
@compare_with = User.find(params[:compare_with])
I have user_ids = [current_user.id,@compare_with.id]
@movies = Movie.joins("usermovies").where('usermovies.user_id' => user_ids)
错误:
Mysql2::Error: Unknown table 'movies': SELECT `movies`.* FROM `movies` usermovies WHERE `usermovies`.`user_id` IN (3, 1)
Extracted source (around line #9):
6: <td><%= "#{@compare_with.name}'s rating" %> </td>
7: </thead>
8: <tbody>
9: <% @movies.each do |movie| %>
10: <td></td>
11: <td></td>
12: <% end %>
但是当我使用它:includes
而不是:joins
它时效果很好。
任何想法代码有什么问题?