class Page < ActiveRecord::Base
has_many :left_page_associations, :foreign_key => :left_page_id,
:class_name => 'PageAssociation'
has_many :left_associations, :through => :left_page_associations,
:source => :right_page
has_many :right_page_associations, :foreign_key => :right_page_id,
:class_name => 'PageAssociation'
has_many :right_associations, :through => :right_page_associations,
:source => :left_page
def associations
(left_associations + right_associations).flatten.uniq
end
end
class PageAssociation < ActiveRecord::Base
belongs_to :left_page, :class_name => 'Page'
belongs_to :right_page, :class_name => 'Page'
end
class Page < ActiveRecord::Base
has_many :left_page_associations, :foreign_key => :left_page_id,
:class_name => 'PageAssociation'
has_many :left_associations, :through => :left_page_associations,
:source => :right_page
has_many :right_page_associations, :foreign_key => :right_page_id,
:class_name => 'PageAssociation'
has_many :right_associations, :through => :right_page_associations,
:source => :left_page
end
Code Example |
---|
Ruby :: rails edit models |
Ruby :: sentry send error manually ruby |
Ruby :: sequel ruby alias table |
Ruby :: next rails gem |
Ruby :: ruby clear set |
Ruby :: ruby rspec change matcher |
Ruby :: Error occurred while parsing request parameters. |
Ruby :: run bundle without production in rails |
Ruby :: How to handle permission in rails |
Ruby :: name error on ruby |
Ruby :: ruby zip rows and columns |
Ruby :: ruby create object with attributes |
Ruby :: rails db:drop not working |
Ruby :: rails has_many through source 1 |
Ruby :: rails print number with space |
Ruby :: rails group every 10 items in array |
Ruby :: ruby array join |
R :: r find elements in common between vectors |
R :: R p value star |
R :: read csv in r |
R :: how to eliminate duplicates in a column in r |
R :: comments in r |
R :: how to change the index of a dataframe in r |
R :: show 2 plots together |
R :: r find nas in dataframe |
R :: strtrim in r |
R :: predict in r stack |
R :: copy list R |
R :: R currency ggplot axis |
R :: R difference | and || |