I have a standard associations belongs_to, has_many :through
class Shop < ActiveRecord::Base
has_many :categories, :through => :shop_categories
class Category < ActiveRecord::Base
has_many :shops, :through => :shop_categories
class ShopCategory < ActiveRecord::Base
There is one root category with hierarchical data for shops.
shop_categories are holding some common fields for shop and category.
mixed one record for one shop and category. So, for 100 categories, in
shop_categories are 200 records, one for each shop.
For this example I have 2 shops.
Shop.first.category.find(10).shop_categories Rails are returning 2
shop_categories records one for each shop. Something is wrong with
associations because it should find in shop_categories all records for
What I need is to retrieve only one record from shop_categories for
I have tried has_one :shop_category but it returns not one but first and
always same never less if I try
So, what is really happening with this association?
I realy can not guess, and I have tried all sort of things with no
Logically this kind of chaining
Shop.find(2).category.find(10).shop_categories should collect and join
appropriate associations and return data only for shop 2.
Could any one give some clues? Or clarify this kind of relation. Maybe
there is another way to retrieve this single data?