I have the following models
venues(id, name, ....)
categories(id, name, ....)
categories_venues(id, venue_id, category_id)
I want to query venues based which have the relation of Categories ID = (1)/(2) or (1 and 2)
How can i do a where query for the relation of a HABTM?
EDIT
Using the following query it solved the problem.
venues = Venue.joins(:categories_venues).where(:categories_venues => {:category_id => values})
I want to exclude repetitive records from the query and a particular ID from the results?
---
- !ruby/object:Venue
attributes:
id: 2
name: Ooty
slug: ooty
created_at: 2014-06-21 22:10:52.000000000 Z
updated_at: 2014-07-05 17:33:26.000000000 Z
- !ruby/object:Venue
attributes:
id: 4
name: Munnar
slug: munnar
created_at: 2014-08-25 03:42:13.000000000 Z
updated_at: 2014-08-25 03:42:13.000000000 Z
- !ruby/object:Venue
attributes:
id: 2
name: Ooty
slug: ooty
created_at: 2014-06-21 22:10:52.000000000 Z
updated_at: 2014-07-05 17:33:26.000000000 Z