I have the following model in rails application
category => company => store
Store has a belongs_to company and company has a belongs_to category relationship.
now i want to use a where method on a store object to retrieve all stores within the same category.
I would like to have something like this
@stores.nearbys(5).where("stores.company.category_id = xxx")
can somebody give me a tip on this
Try joins with where on the joined table:
EDIT:
To get the category of a store you will first have to delegate the category method to its company:
Now just call the method in your query: