Skip to content

Instantly share code, notes, and snippets.

@nathanjsharpe
Created November 17, 2012 21:55
Show Gist options
  • Save nathanjsharpe/4100573 to your computer and use it in GitHub Desktop.
Save nathanjsharpe/4100573 to your computer and use it in GitHub Desktop.
Has many through example
class ServiceElement < ActiveRecord::Base
attr_accessible :body, :title, :category, :source, :number, :file
has_many :parts
has_many :presentations, through: :parts, order: "presentations.date"
end
class Part < ActiveRecord::Base
attr_accessible :position, :presentation_id, :service_element_id
belongs_to :presentation
belongs_to :service_element
end
class Presentation < ActiveRecord::Base
attr_accessible :date, :theme, :service_element_ids
has_many :parts
has_many :service_elements, through: :parts, order: "position"
default_scope order("date DESC")
default_scope include: :parts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment