diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-13 02:06:06 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-13 02:47:46 +0900 |
commit | 0ee96d13de29680e148ccb8e5b68025f29fd091c (patch) | |
tree | e8e2095bc74f34b8a0447cace738368e8ff79bef /activerecord/test/models | |
parent | ed9acb4fcc793ce1ab68a0e5076dc9458cc7f218 (diff) | |
download | rails-0ee96d13de29680e148ccb8e5b68025f29fd091c.tar.gz rails-0ee96d13de29680e148ccb8e5b68025f29fd091c.tar.bz2 rails-0ee96d13de29680e148ccb8e5b68025f29fd091c.zip |
Fix `pluck` and `select` with custom attributes
Currently custom attributes are always qualified by the table name in
the generated SQL wrongly even if the table doesn't have the named
column, it would cause an invalid SQL error.
Custom attributes should only be qualified if the table has the same
named column.
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/company.rb | 2 | ||||
-rw-r--r-- | activerecord/test/models/contract.rb | 8 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 1 |
3 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 838f515aad..a0f48d23f1 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -13,6 +13,8 @@ class Company < AbstractCompany has_many :contracts has_many :developers, through: :contracts + attribute :metadata, :json + scope :of_first_firm, lambda { joins(account: :firm). where("firms.id" => 1) diff --git a/activerecord/test/models/contract.rb b/activerecord/test/models/contract.rb index 3f663375c4..89719775c4 100644 --- a/activerecord/test/models/contract.rb +++ b/activerecord/test/models/contract.rb @@ -5,7 +5,9 @@ class Contract < ActiveRecord::Base belongs_to :developer, primary_key: :id belongs_to :firm, foreign_key: "company_id" - before_save :hi + attribute :metadata, :json + + before_save :hi, :update_metadata after_save :bye attr_accessor :hi_count, :bye_count @@ -19,6 +21,10 @@ class Contract < ActiveRecord::Base @bye_count ||= 0 @bye_count += 1 end + + def update_metadata + self.metadata = { company_id: company_id, developer_id: developer_id } + end end class NewContract < Contract diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index e32cc59399..65d1fce66d 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -31,6 +31,7 @@ class Post < ActiveRecord::Base belongs_to :author_with_posts, -> { includes(:posts) }, class_name: "Author", foreign_key: :author_id belongs_to :author_with_address, -> { includes(:author_address) }, class_name: "Author", foreign_key: :author_id + belongs_to :author_with_select, -> { select(:id) }, class_name: "Author", foreign_key: :author_id def first_comment super.body |