Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Either enable custom association options or set inverse_of for the relations #50

Open
juhazi opened this issue Jun 16, 2016 · 3 comments

Comments

@juhazi
Copy link

juhazi commented Jun 16, 2016

The associations generated by groupify and has_members methods lack the inverse_of option.

It should be possible to enable this on a per-call basis to keep backwards compatibility.

Example usage:

class Organization < Group
  has_members :managers,
    inverse_of: true
end

Which would generate

class Organization < ActiveRecord::Base
  has_many :managers,
    through: :group_memberships_as_group,
    inverse_of: :organizations,
    ... # The rest of the options 
end

Alternatively allow the developer to merge in a (whitelisted?) set of extra keys to the association options hash.

Example of that:

class Organization < Group
  has_members :managers,
    inverse_of: :organizations
end

For more info on inverse_of specifically: https://www.viget.com/articles/exploring-the-inverse-of-option-on-rails-model-associations

@dwbutler
Copy link
Owner

I would be in favor of passing in association options.

For inverse_of specifically, in Rails 4 it is usually inferred automatically, so it doesn't need to be specified unless the names don't match up. So association options would allow that configuration to be put in place.

@juhazi
Copy link
Author

juhazi commented Jul 3, 2016

I started work in 3179b3e

If it looks ok I'll replicate it for all relations and merge with #49 for a PR.

@joelvh
Copy link
Collaborator

joelvh commented Aug 10, 2017

@juhazi Please check out #61 - it allows you to specify custom association options using the has_group or has_member helpers for each association you want to create rather than using has_groups or has_members. Let me know if this does what you need. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants