diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-05-02 14:55:55 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-02 14:55:55 -0700 |
commit | c5305f6fdfd46349a6f0646c3e599b9ed706f59a (patch) | |
tree | cc029a4a586b8e630920fb326dad312c5e85cfcf | |
parent | a23846e0ab2335246cabad08550fa5c77ceb8332 (diff) | |
parent | 8d64cd86db1bc5e1ad119d13eb14f94726a0765f (diff) | |
download | rails-c5305f6fdfd46349a6f0646c3e599b9ed706f59a.tar.gz rails-c5305f6fdfd46349a6f0646c3e599b9ed706f59a.tar.bz2 rails-c5305f6fdfd46349a6f0646c3e599b9ed706f59a.zip |
Merge pull request #28961 from maclover7/jm-fix-28959
Add type caster to `RuntimeReflection#alias_name`
-rw-r--r-- | activerecord/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/enum_test.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/author.rb | 1 | ||||
-rw-r--r-- | activerecord/test/models/book.rb | 2 |
5 files changed, 13 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 37d1a173e0..2e059805a2 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,9 @@ +* Add type caster to `RuntimeReflection#alias_name` + + Fixes #28959. + + *Jon Moss* + * Deprecate `supports_statement_cache?`. *Ryuta Kamizono* diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 5ce134d6b7..1a9e0a4a40 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -1105,7 +1105,7 @@ module ActiveRecord end def alias_name - Arel::Table.new(table_name) + Arel::Table.new(table_name, type_caster: klass.type_caster) end def all_includes; yield; end diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index b7641fcf32..7f63bb2473 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -1,10 +1,12 @@ require "cases/helper" +require "models/author" require "models/book" class EnumTest < ActiveRecord::TestCase - fixtures :books + fixtures :books, :authors setup do + @author = authors(:david) @book = books(:awdr) end @@ -55,6 +57,7 @@ class EnumTest < ActiveRecord::TestCase assert_not_equal @book, Book.where(status: :written).first assert_equal @book, Book.where(status: [:published]).first assert_not_equal @book, Book.where(status: [:written]).first + assert_not @author.unpublished_books.include?(@book) assert_not_equal @book, Book.where.not(status: :published).first assert_equal @book, Book.where.not(status: :written).first end diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb index fab613afd1..2d9cba77e0 100644 --- a/activerecord/test/models/author.rb +++ b/activerecord/test/models/author.rb @@ -106,6 +106,7 @@ class Author < ActiveRecord::Base has_many :tags_with_primary_key, through: :posts has_many :books + has_many :unpublished_books, -> { where(status: [:proposed, :written]) }, class_name: "Book" has_many :subscriptions, through: :books has_many :subscribers, -> { order("subscribers.nick") }, through: :subscriptions has_many :distinct_subscribers, -> { select("DISTINCT subscribers.*").order("subscribers.nick") }, through: :subscriptions, source: :subscriber diff --git a/activerecord/test/models/book.rb b/activerecord/test/models/book.rb index 17bf3fbcb4..5f8a8a96dd 100644 --- a/activerecord/test/models/book.rb +++ b/activerecord/test/models/book.rb @@ -1,5 +1,5 @@ class Book < ActiveRecord::Base - has_many :authors + belongs_to :author has_many :citations, foreign_key: "book1_id" has_many :references, -> { distinct }, through: :citations, source: :reference_of |