method
through_model
v4.1.8 -
Show latest stable
-
0 notes -
Class: HasAndBelongsToMany
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
through_model()
public
Hide source
# File activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb, line 44 def through_model habtm = JoinTableResolver.build lhs_model, association_name, options join_model = Class.new(ActiveRecord::Base) { class << self; attr_accessor :class_resolver attr_accessor :name attr_accessor :table_name_resolver attr_accessor :left_reflection attr_accessor :right_reflection end def self.table_name table_name_resolver.join_table end def self.compute_type(class_name) class_resolver.compute_type class_name end def self.add_left_association(name, options) belongs_to name, options self.left_reflection = _reflect_on_association(name) end def self.add_right_association(name, options) rhs_name = name.to_s.singularize.to_sym belongs_to rhs_name, options self.right_reflection = _reflect_on_association(rhs_name) end def hash object_id.hash end def ==(other) equal?(other) end alias :eql? :== } join_model.name = "HABTM_#{association_name.to_s.camelize}" join_model.table_name_resolver = habtm join_model.class_resolver = lhs_model join_model.add_left_association :left_side, class: lhs_model join_model.add_right_association association_name, belongs_to_options(options) join_model end