mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Don't include inheritance column in the through_scope_attributes
This commit is contained in:
parent
0c2fbc5095
commit
30b76e5575
3 changed files with 17 additions and 2 deletions
|
@ -93,7 +93,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def through_scope_attributes
|
||||
scope.where_values_hash(through_association.reflection.name.to_s).except!(through_association.reflection.foreign_key)
|
||||
scope.where_values_hash(through_association.reflection.name.to_s).except!(through_association.reflection.foreign_key, through_association.reflection.klass.inheritance_column)
|
||||
end
|
||||
|
||||
def save_through_record(record)
|
||||
|
|
|
@ -1139,4 +1139,12 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|||
assert_equal 2, post.lazy_readers_unscope_skimmers.to_a.size
|
||||
assert_equal 2, post.lazy_people_unscope_skimmers.to_a.size
|
||||
end
|
||||
|
||||
def test_has_many_through_add_with_sti_middle_relation
|
||||
club = SuperClub.create!(name: 'Fight Club')
|
||||
member = Member.create!(name: 'Tyler Durden')
|
||||
|
||||
club.members << member
|
||||
assert_equal 1, SuperMembership.where(member_id: member.id, club_id: club.id).count
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ class Club < ActiveRecord::Base
|
|||
has_one :sponsor
|
||||
has_one :sponsored_member, :through => :sponsor, :source => :sponsorable, :source_type => "Member"
|
||||
belongs_to :category
|
||||
|
||||
|
||||
has_many :favourites, -> { where(memberships: { favourite: true }) }, through: :memberships, source: :member
|
||||
|
||||
private
|
||||
|
@ -14,3 +14,10 @@ class Club < ActiveRecord::Base
|
|||
"I'm sorry sir, this is a *private* club, not a *pirate* club"
|
||||
end
|
||||
end
|
||||
|
||||
class SuperClub < ActiveRecord::Base
|
||||
self.table_name = "clubs"
|
||||
|
||||
has_many :memberships, :class_name => "SuperMembership", :foreign_key => "club_id"
|
||||
has_many :members, :through => :memberships
|
||||
end
|
Loading…
Reference in a new issue