Class: DynamicActiveModel::HasManyThrough
- Inherits:
-
Object
- Object
- DynamicActiveModel::HasManyThrough
- Defined in:
- lib/dynamic-active-model/has_many_through.rb
Overview
Adds has_many :through associations across join models. A join model is a table with a primary key and a unique index on exactly two columns, each a belongs_to to a different model; other columns (timestamps, audit columns, extra data) don't matter. For user_roles with a unique (user_id, role_id):
User has_many :roles, through: :user_roles, source: :role
Role has_many :users, through: :user_roles, source: :user
A name already taken on the model (association, method or column) is skipped. Tables without a primary key are has_and_belongs_to_many join tables instead.
Instance Method Summary collapse
- #build! ⇒ void
-
#initialize(models, table_indexes) ⇒ HasManyThrough
constructor
A new instance of HasManyThrough.
Constructor Details
#initialize(models, table_indexes) ⇒ HasManyThrough
Returns a new instance of HasManyThrough.
17 18 19 20 |
# File 'lib/dynamic-active-model/has_many_through.rb', line 17 def initialize(models, table_indexes) @models = models @table_indexes = table_indexes end |
Instance Method Details
#build! ⇒ void
This method returns an undefined value.
23 24 25 |
# File 'lib/dynamic-active-model/has_many_through.rb', line 23 def build! @models.each { |model| add_through_associations(model) } end |