From 59626c5684aea7904239e323224eafdfbe89f64a Mon Sep 17 00:00:00 2001 From: Joel Van Horn Date: Wed, 10 May 2017 17:35:56 -0400 Subject: [PATCH] Use ActiveRecord `base_class` in case member is STI --- lib/groupify/adapter/active_record/group.rb | 4 ++-- lib/groupify/adapter/active_record/group_member.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/groupify/adapter/active_record/group.rb b/lib/groupify/adapter/active_record/group.rb index 40396b0..695479a 100644 --- a/lib/groupify/adapter/active_record/group.rb +++ b/lib/groupify/adapter/active_record/group.rb @@ -51,10 +51,10 @@ def merge!(source) module ClassMethods def with_member(member) - #joins(:group_memberships).where(group_memberships: {member_id: member.id, member_type: member.class.model_name.to_s}) + #joins(:group_memberships).where(group_memberships: {member_id: member.id, member_type: member.class.base_class.to_s}) #member.groups joins(:group_memberships_as_group). - where(group_memberships: {member_id: member.id, member_type: member.class.model_name.to_s}). + where(group_memberships: {member_id: member.id, member_type: member.class.base_class.to_s}). extending(Groupify::ActiveRecord::GroupMember::GroupAssociationExtensions) end diff --git a/lib/groupify/adapter/active_record/group_member.rb b/lib/groupify/adapter/active_record/group_member.rb index 7f55e61..ecf1940 100644 --- a/lib/groupify/adapter/active_record/group_member.rb +++ b/lib/groupify/adapter/active_record/group_member.rb @@ -48,7 +48,7 @@ def <<(*args) to_add_directly << group unless include?(group) # add a second entry for the given membership type if membership_type - membership = group.group_memberships_as_group.where(member_id: member.id, member_type: member.class.model_name.to_s, membership_type: membership_type).first_or_initialize + membership = group.group_memberships_as_group.where(member_id: member.id, member_type: member.class.base_class.to_s, membership_type: membership_type).first_or_initialize to_add_with_membership_type << membership unless membership.persisted? end group.__send__(:clear_association_cache)