aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/from_clause.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-01-26 16:36:14 -0700
committerSean Griffin <sean@thoughtbot.com>2015-01-26 16:36:14 -0700
commitbdc5141652770fd227455681cde1f9899f55b0b9 (patch)
treecace53ff2962478db07e47a8e6443523815750be /activerecord/lib/active_record/relation/from_clause.rb
parent8436e2c2bd91c1a57fb1273218a5428cc2c6b45a (diff)
downloadrails-bdc5141652770fd227455681cde1f9899f55b0b9.tar.gz
rails-bdc5141652770fd227455681cde1f9899f55b0b9.tar.bz2
rails-bdc5141652770fd227455681cde1f9899f55b0b9.zip
Move the `from` bind logic to a `FromClause` class
Contrary to my previous commit message, it wasn't overkill, and led to much cleaner code. [Sean Griffin & anthonynavarre]
Diffstat (limited to 'activerecord/lib/active_record/relation/from_clause.rb')
-rw-r--r--activerecord/lib/active_record/relation/from_clause.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/from_clause.rb b/activerecord/lib/active_record/relation/from_clause.rb
new file mode 100644
index 0000000000..fc16ac58b4
--- /dev/null
+++ b/activerecord/lib/active_record/relation/from_clause.rb
@@ -0,0 +1,32 @@
+module ActiveRecord
+ class Relation
+ class FromClause
+ attr_reader :value, :name
+
+ def initialize(value, name)
+ @value = value
+ @name = name
+ end
+
+ def binds
+ if value.is_a?(Relation)
+ value.arel.bind_values + value.bind_values
+ else
+ []
+ end
+ end
+
+ def merge(other)
+ self
+ end
+
+ def empty?
+ value.nil?
+ end
+
+ def self.empty
+ new(nil, nil)
+ end
+ end
+ end
+end