My Campaign model has_many Response.
What I'd like to do is a search that's like Campaign.where.not(responses.nil?)
Basically returning a list of all campaigns that have responses.
What's the best way to do this?
You may do it by query with join:
Campaign.joins(:responses)
Or by two queries without join:
Campaign.where(id: Response.pluck(:campaign_id))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With