I have this query put together which performs fine.
search = Artist.where(:status => "active").where("upcoming_events_count > 0").order("echonest_external_popularity DESC").limit(limit))
The issue is that I’d like to add one more check, which is on another table ArtistPhoto. The match needs to make sure that the Artist (from the artist_id) also contains a valid photo.
I have the query working find independently:
ArtistPhoto.where("artist_id = ? and artist_photos.primary = ?", self.id, true).first
If anyone can assist with getting the join into 1 query that would be great.
Thanks
Use
joinsto add the other association:This answer assumes you have a
has_many :artist_photoson yourArtistmodel.