Created
November 17, 2012 21:55
-
-
Save nathanjsharpe/4100573 to your computer and use it in GitHub Desktop.
Has many through example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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