dwbutler / groupify

Add group and membership functionality to your Rails models
MIT License
194 stars 42 forks source link

Add the `has_member` and `has_group` association helpers to specify model class name #60

Closed joelvh closed 7 years ago

joelvh commented 7 years ago

We wanted to create a users association with a CustomUser class. We added the option to use has_member :users, class_name: 'CustomUser', so you can specify the class for specific associations. This is backwards compatible with just passing in association names to has_members.

I think that the only change that's missing from Mongoid is default_members: true option for has_member

dwbutler commented 7 years ago

I understand the need to customize the associations generated by Groupify.

In this case, I think it will ultimately be simpler and more useful to have a separate has_member method which takes an association name and a hash of association options.

has_member :users, class_name: 'CustomUserClass'
has_member :admins, class_name: 'CustomAdminClass'
joelvh commented 7 years ago

@dwbutler OK, I will refactor with has_member method and take a look at the tests that are failing.

joelvh commented 7 years ago

@dwbutler updated with has_member method. I also noticed that there was a missing association_name argument to the associate_member_class method in Mongoid, which is now added....

dwbutler commented 7 years ago

Related: https://github.com/dwbutler/groupify/issues/47

joelvh commented 7 years ago

@dwbutler closing this in favor of #61, which incorporates this addition.