diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_relation/relations/aggregation.rb | 1 | ||||
-rw-r--r-- | lib/active_relation/relations/alias.rb | 2 | ||||
-rw-r--r-- | lib/active_relation/relations/join.rb | 21 | ||||
-rw-r--r-- | lib/active_relation/relations/rename.rb | 4 | ||||
-rw-r--r-- | lib/active_relation/relations/table.rb | 2 |
5 files changed, 11 insertions, 19 deletions
diff --git a/lib/active_relation/relations/aggregation.rb b/lib/active_relation/relations/aggregation.rb index 9e803b3587..7910223673 100644 --- a/lib/active_relation/relations/aggregation.rb +++ b/lib/active_relation/relations/aggregation.rb @@ -21,7 +21,6 @@ module ActiveRelation expressions.collect { |e| e.bind(self) } end - protected def aggregation? true end diff --git a/lib/active_relation/relations/alias.rb b/lib/active_relation/relations/alias.rb index 5b45d9dce4..941a95c58e 100644 --- a/lib/active_relation/relations/alias.rb +++ b/lib/active_relation/relations/alias.rb @@ -3,7 +3,7 @@ module ActiveRelation attr_reader :alias def aliased_prefix_for(attribute) - @alias + self[attribute] and @alias end def initialize(relation, aliaz) diff --git a/lib/active_relation/relations/join.rb b/lib/active_relation/relations/join.rb index 4c4f2e66a2..c61680fd55 100644 --- a/lib/active_relation/relations/join.rb +++ b/lib/active_relation/relations/join.rb @@ -20,20 +20,22 @@ module ActiveRelation def attributes [ - relation1.aggregation?? relation1.attributes.collect(&:to_attribute) : relation1.attributes, - relation2.aggregation?? relation2.attributes.collect(&:to_attribute) : relation2.attributes, + relation1.attributes.collect(&:to_attribute), + relation2.attributes.collect(&:to_attribute), ].flatten.collect { |a| a.bind(self) } end def prefix_for(attribute) - (relation1[attribute] && relation1.aliased_prefix_for(attribute)) || - (relation2[attribute] && relation2.aliased_prefix_for(attribute)) + relation1.aliased_prefix_for(attribute) or + relation2.aliased_prefix_for(attribute) end alias_method :aliased_prefix_for, :prefix_for protected def joins - [relation1.joins, relation2.joins, join].compact.join(" ") + right_table_sql = relation2.aggregation?? relation2.to_sql(Sql::Aggregation.new) : relation2.send(:table_sql) + this_join = [join_sql, right_table_sql, "ON", predicates.collect { |p| p.bind(self).to_sql(Sql::Predicate.new) }.join(' AND ')].join(" ") + [relation1.joins, relation2.joins, this_join].compact.join(" ") end def selects @@ -46,14 +48,5 @@ module ActiveRelation def table_sql relation1.aggregation?? relation1.to_sql(Sql::Aggregation.new) : relation1.send(:table_sql) end - - private - def join - [join_sql, right_table_sql, "ON", predicates.collect { |p| p.bind(self).to_sql(Sql::Predicate.new) }.join(' AND ')].join(" ") - end - - def right_table_sql - relation2.aggregation?? relation2.to_sql(Sql::Aggregation.new) : relation2.send(:table_sql) - end end end
\ No newline at end of file diff --git a/lib/active_relation/relations/rename.rb b/lib/active_relation/relations/rename.rb index 6b1b29bf75..20e79ebefb 100644 --- a/lib/active_relation/relations/rename.rb +++ b/lib/active_relation/relations/rename.rb @@ -8,8 +8,8 @@ module ActiveRelation end def ==(other) - self.class == other.class and - relation == other.relation and + self.class == other.class and + relation == other.relation and attribute == other.attribute and pseudonym == other.pseudonym end diff --git a/lib/active_relation/relations/table.rb b/lib/active_relation/relations/table.rb index c8ccb22fdd..d85c268019 100644 --- a/lib/active_relation/relations/table.rb +++ b/lib/active_relation/relations/table.rb @@ -17,7 +17,7 @@ module ActiveRelation end def prefix_for(attribute) - name + self[attribute] and name end alias_method :aliased_prefix_for, :prefix_for |