Skip to content

Commit

Permalink
Use ActiveRecord base_class in case member is STI
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvh committed May 10, 2017
1 parent aa8411c commit 1a598c9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/groupify/adapter/active_record/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/groupify/adapter/active_record/group_member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1a598c9

Please sign in to comment.