diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-02 15:40:11 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-02 15:40:11 -0700 |
commit | 7963c5d841c2c518d1087558f51a904060a9d305 (patch) | |
tree | bd5ed6d7da56a3153e9cd1e5f1e4364d999d1973 /activerecord/lib/active_record/associations | |
parent | 0af978d33489c3ab54084c26d1354837b16f0cf5 (diff) | |
download | rails-7963c5d841c2c518d1087558f51a904060a9d305.tar.gz rails-7963c5d841c2c518d1087558f51a904060a9d305.tar.bz2 rails-7963c5d841c2c518d1087558f51a904060a9d305.zip |
have the builder create the middle reflection
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb index 4b47824148..2f79976594 100644 --- a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb +++ b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb @@ -80,6 +80,19 @@ module ActiveRecord::Associations::Builder join_model end + def middle_reflection(join_model) + middle_name = [lhs_model.name.downcase.pluralize, + association_name].join('_').gsub(/::/, '_').to_sym + middle_options = middle_options join_model + hm_builder = HasMany.create_builder(lhs_model, + middle_name, + nil, + middle_options) + hm_builder.build lhs_model + end + + private + def middle_options(join_model) middle_options = {} middle_options[:class] = join_model @@ -90,8 +103,6 @@ module ActiveRecord::Associations::Builder middle_options end - private - def belongs_to_options(options) rhs_options = {} |