Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Item < ActiveRecord::Base
- has_many :catalog_items
- has_many :catalogs, :through => :catalog_items
- end
- @item = Item.find(4)
- @catalog = @item.catalogs.first
- @cat_item = @item.catalog_items.first(:conditions => {:catalog_id => @catalog.id})
- position = @cat_item.position
- class Item < ActiveRecord::Base
- has_many :catalog_items
- has_many :catalogs, :through => :catalog_items, :select => "catalogue_items.position, catalogs.*"
- end
- # which is basically same as your "frustrating way" of doing it
- @item.catalog_items.find_by_catalogue_id(@item.catalogs.first.id).position
- def position_in_first_catalogue
- self.catalog_items.find_by_catalogue_id(self.catalogs.first.id).position
- end
- @item.position_in_first_catalogue
- class Catalog < ActiveRecord::Base
- belongs_to :catalog_item
- end
- @item = Item.find(4)
- position = @item.catalog_items.first.position
Add Comment
Please, Sign In to add comment