Class: ActiveRecord::Associations::Preloader::HasAndBelongsToMany
- Inherits:
-
CollectionAssociation
- Object
- Association
- CollectionAssociation
- ActiveRecord::Associations::Preloader::HasAndBelongsToMany
- Defined in:
- lib/active_record/associations/preloader/has_and_belongs_to_many.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#join_table ⇒ Object
readonly
Returns the value of attribute join_table.
Attributes inherited from Association
#klass, #model, #owners, #preload_options, #reflection
Instance Method Summary collapse
- #association_key ⇒ Object
- #association_key_name ⇒ Object
-
#initialize(klass, records, reflection, preload_options) ⇒ HasAndBelongsToMany
constructor
A new instance of HasAndBelongsToMany.
- #owner_key_name ⇒ Object
-
#records_for(ids) ⇒ Object
Unlike the other associations, we want to get a raw array of rows so that we can access the aliased column on the join table.
Methods inherited from Association
#options, #owners_by_key, #preload, #run, #scoped, #table
Constructor Details
#initialize(klass, records, reflection, preload_options) ⇒ HasAndBelongsToMany
Returns a new instance of HasAndBelongsToMany.
7 8 9 10 |
# File 'lib/active_record/associations/preloader/has_and_belongs_to_many.rb', line 7 def initialize(klass, records, reflection, ) super @join_table = Arel::Table.new([:join_table]).alias('t0') end |
Instance Attribute Details
#join_table ⇒ Object (readonly)
Returns the value of attribute join_table.
5 6 7 |
# File 'lib/active_record/associations/preloader/has_and_belongs_to_many.rb', line 5 def join_table @join_table end |
Instance Method Details
#association_key ⇒ Object
27 28 29 |
# File 'lib/active_record/associations/preloader/has_and_belongs_to_many.rb', line 27 def association_key join_table[reflection.foreign_key] end |
#association_key_name ⇒ Object
23 24 25 |
# File 'lib/active_record/associations/preloader/has_and_belongs_to_many.rb', line 23 def association_key_name 'ar_association_key_name' end |
#owner_key_name ⇒ Object
19 20 21 |
# File 'lib/active_record/associations/preloader/has_and_belongs_to_many.rb', line 19 def owner_key_name reflection.active_record_primary_key end |
#records_for(ids) ⇒ Object
Unlike the other associations, we want to get a raw array of rows so that we can access the aliased column on the join table
14 15 16 17 |
# File 'lib/active_record/associations/preloader/has_and_belongs_to_many.rb', line 14 def records_for(ids) scope = super klass.connection.select_all(scope.arel, 'SQL', scope.bind_values) end |