1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #15772 from nbudin/sti_through_bug

Don't include inheritance column in the through_scope_attributes
This commit is contained in:
Rafael Mendonça França 2014-06-19 15:04:39 -03:00
commit 9ac81b954a
3 changed files with 18 additions and 1 deletions

View file

@ -93,7 +93,9 @@ 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)

View file

@ -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

View file

@ -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