A have 3 Models: Trailer, Movie, Release. Trailer belongs_to a Movie, and a Movie has_many releases and has_many trailers.
I want to render the first trailer of each movie that has a release.
My approach was to create a scope in Trailer.rb:
scope :released, -> {
joins(:movie).
where("trailers.movie_id = movies.id").
joins(:release).
where.not( :release => nil )
}
So that I could then call Trailer.released but my query is not working, instead of returning a collection, it's returning an active record relation.
- Where am I going wrong with my query?
- Is there a more efficient way to do this?
first, for example, on it. It should spit out either the object or the error, saying what's wrong with the query