diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2017-07-18 15:41:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-18 15:41:02 -0400 |
commit | a03a7ce50b9dfe4a13f0cd11b69a093a5bcfd7e9 (patch) | |
tree | e16061820d2a896cf76d69b6574461a848096b8b /activerecord | |
parent | a6d6e90fa90eedbdb6d3cda679aa4b47ddfa7315 (diff) | |
parent | 452a814cf014a6fbd33c380b8f7c13b03edaa531 (diff) | |
download | rails-a03a7ce50b9dfe4a13f0cd11b69a093a5bcfd7e9.tar.gz rails-a03a7ce50b9dfe4a13f0cd11b69a093a5bcfd7e9.tar.bz2 rails-a03a7ce50b9dfe4a13f0cd11b69a093a5bcfd7e9.zip |
Merge pull request #29033 from kamipo/make_preload_query_to_prepared_statements
Make preload query to preparable
Diffstat (limited to 'activerecord')
4 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index 698fd29beb..d0964ee4fd 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -103,7 +103,7 @@ module ActiveRecord end def records_for(ids, &block) - scope.where(association_key_name => ids).load(&block) + scope.where(association_key_name => ids.size == 1 ? ids.first : ids).load(&block) end def scope diff --git a/activerecord/test/cases/adapters/postgresql/explain_test.rb b/activerecord/test/cases/adapters/postgresql/explain_test.rb index d79fbccf47..3d5684704e 100644 --- a/activerecord/test/cases/adapters/postgresql/explain_test.rb +++ b/activerecord/test/cases/adapters/postgresql/explain_test.rb @@ -15,6 +15,6 @@ class PostgreSQLExplainTest < ActiveRecord::PostgreSQLTestCase explain = Developer.where(id: 1).includes(:audit_logs).explain assert_match %(QUERY PLAN), explain assert_match %r(EXPLAIN for: SELECT "developers"\.\* FROM "developers" WHERE "developers"\."id" = (?:\$1 \[\["id", 1\]\]|1)), explain - assert_match %(EXPLAIN for: SELECT "audit_logs".* FROM "audit_logs" WHERE "audit_logs"."developer_id" = 1), explain + assert_match %r(EXPLAIN for: SELECT "audit_logs"\.\* FROM "audit_logs" WHERE "audit_logs"\."developer_id" = (?:\$1 \[\["developer_id", 1\]\]|1)), explain end end diff --git a/activerecord/test/cases/adapters/sqlite3/explain_test.rb b/activerecord/test/cases/adapters/sqlite3/explain_test.rb index 29d97ae78c..b907a7ae0f 100644 --- a/activerecord/test/cases/adapters/sqlite3/explain_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/explain_test.rb @@ -15,7 +15,7 @@ class SQLite3ExplainTest < ActiveRecord::SQLite3TestCase explain = Developer.where(id: 1).includes(:audit_logs).explain assert_match %r(EXPLAIN for: SELECT "developers"\.\* FROM "developers" WHERE "developers"\."id" = (?:\? \[\["id", 1\]\]|1)), explain assert_match(/(SEARCH )?TABLE developers USING (INTEGER )?PRIMARY KEY/, explain) - assert_match %(EXPLAIN for: SELECT "audit_logs".* FROM "audit_logs" WHERE "audit_logs"."developer_id" = 1), explain + assert_match %r(EXPLAIN for: SELECT "audit_logs"\.\* FROM "audit_logs" WHERE "audit_logs"\."developer_id" = (?:\? \[\["developer_id", 1\]\]|1)), explain assert_match(/(SCAN )?TABLE audit_logs/, explain) end end diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index fb5a7bcc31..a54480fdb4 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -418,7 +418,7 @@ class InheritanceTest < ActiveRecord::TestCase def test_eager_load_belongs_to_primary_key_quoting con = Account.connection - assert_sql(/#{con.quote_table_name('companies')}\.#{con.quote_column_name('id')} = 1/) do + assert_sql(/#{con.quote_table_name('companies')}\.#{con.quote_column_name('id')} = (?:#{Regexp.quote(bind_param.to_sql)}|1)/) do Account.all.merge!(includes: :firm).find(1) end end |