From 50a8cdf0e2cff604b0361a370afc8becf2579d94 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Mon, 19 Jan 2015 15:09:47 -0700 Subject: Move `create_binds` over to the `PredicateBuilder` I'm looking to introduce a `WhereClause` class to handle most of this logic, and this method will eventually move over to there. However, this intermediate refactoring should make that easier to do. --- activerecord/lib/active_record/table_metadata.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activerecord/lib/active_record/table_metadata.rb') diff --git a/activerecord/lib/active_record/table_metadata.rb b/activerecord/lib/active_record/table_metadata.rb index 11e33e8dfe..31a40adb67 100644 --- a/activerecord/lib/active_record/table_metadata.rb +++ b/activerecord/lib/active_record/table_metadata.rb @@ -22,6 +22,12 @@ module ActiveRecord arel_table[column_name] end + def column(column_name) + if klass + klass.columns_hash[column_name.to_s] + end + end + def associated_with?(association_name) klass && klass._reflect_on_association(association_name) end -- cgit v1.2.3 From 3327cd3f61a22a5834dcbf9bd24ecbc3a23de3de Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Sat, 24 Jan 2015 21:07:55 -0700 Subject: Expand the number of types which can use prepared statements This will allow all types which require no additional handling to use prepared statements. Specifically, this will allow for `true`, `false`, `Date`, `Time`, and any custom PG type to use prepared statements. This also revealed another source of nil columns in bind params, and an inconsistency in their use. The specific inconsistency comes from a nested query coming from a through association, where one of the inversed associations is not bi-directional. The stop-gap is to simply construct the column at the site it is being used. This should simply go away on its own once we use `Attribute` to represent them instead, since we already have all of the information we need. --- activerecord/lib/active_record/table_metadata.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'activerecord/lib/active_record/table_metadata.rb') diff --git a/activerecord/lib/active_record/table_metadata.rb b/activerecord/lib/active_record/table_metadata.rb index 31a40adb67..62a0c04a0f 100644 --- a/activerecord/lib/active_record/table_metadata.rb +++ b/activerecord/lib/active_record/table_metadata.rb @@ -25,6 +25,9 @@ module ActiveRecord def column(column_name) if klass klass.columns_hash[column_name.to_s] + else + # FIXME: We really shouldn't need to do this. + ConnectionAdapters::Column.new(column_name.to_s, nil, Type::Value.new) end end -- cgit v1.2.3 From 6a7ac40dabf4a8948418c61f307ffe52ddcb48f2 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Mon, 26 Jan 2015 15:49:29 -0700 Subject: Go through normal `where` logic in `AssociationScope` This removes the need to duplicate much of the logic in `WhereClause` and `PredicateBuilder`, simplifies the code, removes the need for the connection adapter to be continuously passed around, and removes one place that cares about the internal representation of `bind_values` Part of the larger refactoring to change how binds are represented internally [Sean Griffin & anthonynavarre] --- activerecord/lib/active_record/table_metadata.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/table_metadata.rb') diff --git a/activerecord/lib/active_record/table_metadata.rb b/activerecord/lib/active_record/table_metadata.rb index 62a0c04a0f..3707fd3f04 100644 --- a/activerecord/lib/active_record/table_metadata.rb +++ b/activerecord/lib/active_record/table_metadata.rb @@ -43,7 +43,7 @@ module ActiveRecord association_klass = association.klass arel_table = association_klass.arel_table else - type_caster = TypeCaster::Connection.new(klass.connection, table_name) + type_caster = TypeCaster::Connection.new(klass, table_name) association_klass = nil arel_table = Arel::Table.new(table_name, type_caster: type_caster) end -- cgit v1.2.3 From 6c235dd95812a7c4e8123b6d34d6f3433805ee1c Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 27 Jan 2015 12:07:06 -0700 Subject: Use an `Attribute` object to represent a bind value The column is primarily used for type casting, which we're trying to separate from the idea of a column. Since what we really need is the combination of a name, type, and value, let's use the object that we already have to represent that concept, rather than this tuple. No consumers of the bind values have been changed, only the producers (outside of tests which care too much about internals). This is *finally* possible since the bind values are now produced from a reasonable number of lcoations. --- activerecord/lib/active_record/table_metadata.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record/table_metadata.rb') diff --git a/activerecord/lib/active_record/table_metadata.rb b/activerecord/lib/active_record/table_metadata.rb index 3707fd3f04..6c8792ee80 100644 --- a/activerecord/lib/active_record/table_metadata.rb +++ b/activerecord/lib/active_record/table_metadata.rb @@ -22,12 +22,11 @@ module ActiveRecord arel_table[column_name] end - def column(column_name) + def type(column_name) if klass - klass.columns_hash[column_name.to_s] + klass.type_for_attribute(column_name.to_s) else - # FIXME: We really shouldn't need to do this. - ConnectionAdapters::Column.new(column_name.to_s, nil, Type::Value.new) + Type::Value.new end end -- cgit v1.2.3