diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-07-24 14:50:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-24 14:50:14 -0400 |
commit | 06dff4d7da6bfec842e94e1585cd1af9d048e6a4 (patch) | |
tree | 8e24fef4737eb2c95dc2c94020cdf3fa93983727 /activerecord/test/models | |
parent | 3a4a775732a0512d5ef0c97c2bbeb03110766715 (diff) | |
parent | 3293ca6d38b42582c95ae7f6eaf6c0bd8eef2d65 (diff) | |
download | rails-06dff4d7da6bfec842e94e1585cd1af9d048e6a4.tar.gz rails-06dff4d7da6bfec842e94e1585cd1af9d048e6a4.tar.bz2 rails-06dff4d7da6bfec842e94e1585cd1af9d048e6a4.zip |
Merge pull request #29848 from kamipo/fix_distinct_count_with_order_and_limit
Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT`
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/account.rb | 34 | ||||
-rw-r--r-- | activerecord/test/models/company.rb | 35 |
2 files changed, 35 insertions, 34 deletions
diff --git a/activerecord/test/models/account.rb b/activerecord/test/models/account.rb new file mode 100644 index 0000000000..0c3cd45a81 --- /dev/null +++ b/activerecord/test/models/account.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class Account < ActiveRecord::Base + belongs_to :firm, class_name: "Company" + belongs_to :unautosaved_firm, foreign_key: "firm_id", class_name: "Firm", autosave: false + + alias_attribute :available_credit, :credit_limit + + def self.destroyed_account_ids + @destroyed_account_ids ||= Hash.new { |h, k| h[k] = [] } + end + + # Test private kernel method through collection proxy using has_many. + def self.open + where("firm_name = ?", "37signals") + end + + before_destroy do |account| + if account.firm + Account.destroyed_account_ids[account.firm.id] << account.id + end + end + + validate :check_empty_credit_limit + + private + def check_empty_credit_limit + errors.add("credit_limit", :blank) if credit_limit.blank? + end + + def private_method + "Sir, yes sir!" + end +end diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 50e9553bfe..bbc5fc2b2d 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -187,37 +187,4 @@ end class VerySpecialClient < SpecialClient end -class Account < ActiveRecord::Base - belongs_to :firm, class_name: "Company" - belongs_to :unautosaved_firm, foreign_key: "firm_id", class_name: "Firm", autosave: false - - alias_attribute :available_credit, :credit_limit - - def self.destroyed_account_ids - @destroyed_account_ids ||= Hash.new { |h, k| h[k] = [] } - end - - # Test private kernel method through collection proxy using has_many. - def self.open - where("firm_name = ?", "37signals") - end - - before_destroy do |account| - if account.firm - Account.destroyed_account_ids[account.firm.id] << account.id - end - true - end - - validate :check_empty_credit_limit - - private - - def check_empty_credit_limit - errors.add("credit_limit", :blank) if credit_limit.blank? - end - - def private_method - "Sir, yes sir!" - end -end +require "models/account" |