From 111ccc832bc977b15af12c14e7ca078dad2d4373 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sun, 29 Jan 2017 05:43:45 +0900 Subject: Chain scope constraints should respect own table alias Fixes #27666. --- activerecord/test/models/family.rb | 4 ++++ activerecord/test/models/family_tree.rb | 4 ++++ activerecord/test/models/user.rb | 4 ++++ 3 files changed, 12 insertions(+) create mode 100644 activerecord/test/models/family.rb create mode 100644 activerecord/test/models/family_tree.rb (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/family.rb b/activerecord/test/models/family.rb new file mode 100644 index 0000000000..5ae5a78c95 --- /dev/null +++ b/activerecord/test/models/family.rb @@ -0,0 +1,4 @@ +class Family < ActiveRecord::Base + has_many :family_trees, -> { where(token: nil) } + has_many :members, through: :family_trees +end diff --git a/activerecord/test/models/family_tree.rb b/activerecord/test/models/family_tree.rb new file mode 100644 index 0000000000..cd9829fedd --- /dev/null +++ b/activerecord/test/models/family_tree.rb @@ -0,0 +1,4 @@ +class FamilyTree < ActiveRecord::Base + belongs_to :member, class_name: "User", foreign_key: "member_id" + belongs_to :family +end diff --git a/activerecord/test/models/user.rb b/activerecord/test/models/user.rb index c099c57e37..5089a795f4 100644 --- a/activerecord/test/models/user.rb +++ b/activerecord/test/models/user.rb @@ -7,6 +7,10 @@ class User < ActiveRecord::Base has_and_belongs_to_many :jobs_pool, class_name: "Job", join_table: "jobs_pool" + + has_one :family_tree, -> { where(token: nil) }, foreign_key: "member_id" + has_one :family, through: :family_tree + has_many :family_members, through: :family, source: :members end class UserWithNotification < User -- cgit v1.2.3