Class: MetaWhere::PolymorphicJoinAssociation
- Inherits:
-
ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation
- Object
- ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation
- MetaWhere::PolymorphicJoinAssociation
- Defined in:
- lib/meta_where/join_dependency.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(reflection, join_dependency, polymorphic_class, parent = nil) ⇒ PolymorphicJoinAssociation
constructor
A new instance of PolymorphicJoinAssociation.
- #join_belongs_to_to(relation) ⇒ Object
Constructor Details
#initialize(reflection, join_dependency, polymorphic_class, parent = nil) ⇒ PolymorphicJoinAssociation
Returns a new instance of PolymorphicJoinAssociation.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/meta_where/join_dependency.rb', line 67 def initialize(reflection, join_dependency, polymorphic_class, parent = nil) reflection.check_validity! @active_record = polymorphic_class @cached_record = {} @column_names_with_alias = nil @reflection = reflection.clone @reflection.instance_variable_set :"@klass", polymorphic_class @join_dependency = join_dependency @parent = parent @join_type = Arel::InnerJoin @aliased_prefix = "t#{ join_dependency.join_parts.size }" allocate_aliases @table = Arel::Table.new( table_name, :as => aliased_table_name, :engine => arel_engine ) end |
Instance Method Details
#==(other) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/meta_where/join_dependency.rb', line 86 def ==(other) other.class == self.class && other.reflection == reflection && other.active_record == active_record && other.parent == parent end |
#join_belongs_to_to(relation) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/meta_where/join_dependency.rb', line 93 def join_belongs_to_to(relation) foreign_key = [:foreign_key] || reflection.foreign_key foreign_type = [:foreign_type] || reflection.foreign_type primary_key = [:primary_key] || reflection.klass.primary_key join_target_table( relation, target_table[primary_key].eq(parent_table[foreign_key]). and(parent_table[foreign_type].eq(active_record.name)) ) end |