Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type caster to `RuntimeReflection#alias_name` #28961

Merged
merged 1 commit into from May 2, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,3 +1,9 @@
* Add type caster to `RuntimeReflection#alias_name`

Fixes #28959.

*Jon Moss*

* Deprecate `supports_statement_cache?`.

*Ryuta Kamizono*
@@ -1105,7 +1105,7 @@ def alias_candidate(name)
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
@@ -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
@@ -106,6 +106,7 @@ def ratings
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
@@ -1,5 +1,5 @@
class Book < ActiveRecord::Base
has_many :authors

This comment has been minimized.

Copy link
@rafaelfranca

rafaelfranca May 2, 2017

Member

Do you need to change the association?

This comment has been minimized.

Copy link
@maclover7

maclover7 May 2, 2017

Author Member

The schema has the _id column on the books table, not authors, https://github.com/rails/rails/blob/master/activerecord/test/schema/schema.rb#L55-L61 versus https://github.com/rails/rails/blob/master/activerecord/test/schema/schema.rb#L91

I believe I had to change it to get the test passing. Either way the way it is now is wrong

belongs_to :author

has_many :citations, foreign_key: "book1_id"
has_many :references, -> { distinct }, through: :citations, source: :reference_of
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.