class ItemGroup < ActiveRecord::Base has_many :item_in_groups has_many :items, through: :item_in_groups def all_items(offset, limit) self.items.where(on_display: true).order("item_in_groups.position").limit(limit).offset(offset).all end end