0
我有一個電影模式表加入Rails中的Active Record
class Film < ActiveRecord::Base
has_many :film_genres
has_many :genres, through: :film_genres
end
流派模型
class Genre < ActiveRecord::Base
has_many :film_genres
has_many :films, through: :film_genres
end
,然後我有我的filmGenre模型
class FilmGenre < ActiveRecord::Base
belongs_to :film
belongs_to :genre
end
林試圖得到一個在特定流派下的控制器中的電影列表,但似乎無法加入工作。通過與起始
@films = Film.includes(:genres).where(genres: {id: 4})
或者,它可能是更容易得到所有類型4的電影:
def show
@films = ## need a join/select here to fetch all films with Genre.id of 4
end
你得到了什麼樣的錯誤? – rii