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
- #association_join ⇒ Object
-
#initialize(reflection, join_dependency, polymorphic_class, parent = nil) ⇒ PolymorphicJoinAssociation
constructor
A new instance of PolymorphicJoinAssociation.
Constructor Details
#initialize(reflection, join_dependency, polymorphic_class, parent = nil) ⇒ PolymorphicJoinAssociation
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/meta_where/join_dependency.rb', line 61 def initialize(reflection, join_dependency, polymorphic_class, parent = nil) reflection.check_validity! @active_record = polymorphic_class @cached_record = {} @join_dependency = join_dependency @parent = parent || join_dependency.join_base @reflection = reflection.clone @reflection.instance_variable_set :"@klass", polymorphic_class @aliased_prefix = "t#{ join_dependency.joins.size }" @parent_table_name = @parent.active_record.table_name @aliased_table_name = aliased_table_name_for(table_name) @join = nil @join_type = Arel::Nodes::InnerJoin end |
Instance Method Details
#==(other) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/meta_where/join_dependency.rb', line 76 def ==(other) other.class == self.class && other.reflection == reflection && other.active_record == active_record && other.parent == parent end |
#association_join ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/meta_where/join_dependency.rb', line 83 def association_join return @join if @join aliased_table = Arel::Table.new(table_name, :as => @aliased_table_name, :engine => arel_engine) parent_table = Arel::Table.new(parent.table_name, :as => parent.aliased_table_name, :engine => arel_engine) @join = [ aliased_table[[:primary_key] || reflection.klass.primary_key].eq(parent_table[[:foreign_key] || reflection.primary_key_name]), parent_table[[:foreign_type]].eq(active_record.name) ] if [:conditions] @join << process_conditions([:conditions], aliased_table_name) end @join end |