-
Notifications
You must be signed in to change notification settings - Fork 42
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
Inverse of has_members missing as a feature? #47
Comments
There are a couple important things to understand about the current design of Groupify.
In the sample code above, If you want to enforce that a groupify :group_member, group_class_name: 'Organization' This should work because it will define a new Let me know if this works for you, and I can add a note to the README about this use case. |
I wrote some specs to clarify my intention. has_groups :organizations associationFirst off we define a counterpart to the
then I would expect the following spec to pass(which it does):
So my wish here would be to have a helper to define the association like with has_members :managers scoping issueBut then I noticed that
Is this expected behaviour or is this a bug? (Note that my custom |
So the desired behavior is to have a way to define a custom association which returns a subset of possible groups (filtered by type)? That seems reasonable. The behavior with managers seems like a bug. I would expect the |
Provide a helper for member classes to create associations scoped to certain subclasses of the group class. Having `has_groups :group_subtypes` creates an association `has_many :group_subtypes, through: :group_memberships_as_member`. Differs in exposed interface from mongoid adapter. Issue: dwbutler#47 ( dwbutler#47 )
I have sketched out a suggestion for the helper at the commit referenced above by paraphrasing your work on the PR above. How should the The commit still needs to be merged with your open PR above to ensure compatibility when a model is both a group and a member and also uses both |
@juhazi I started doing similar work last week to support allowing a member to belong to multiple groups (of any class, not just of one base class). Here is as far as I got: https://github.com/dwbutler/groupify/compare/feature/multiple-group-associations It's very similar to the work you did. I ended up calling the method I abandoned this approach when I realized how much work it will be. It will essentially require a rewrite of the entire gem. Everywhere there is encoded the assumption that there is a single Furthermore, it's not clear to me that this approach will be compatible with how the Mongoid adapter is currently implemented, which might necessitate storing custom data structures instead of using the built in Mongoid relations. In any case, we can implement a similar interface here, with the documented restriction that the membership classes must be subclasses of |
So feature-wise my commit would check all the boxes. I'll change the name to yours or should it be This feature should probably be merged after #48 because it has the same Mongoid issue and filtering should work correctly both ways. |
I would stick to naming it |
Taking the active_record_spec example setup with only the relevant parts:
With this,
Organization
class has ahas_many :managers
association.How do I get an
inverse_of
association of that ashas_many :organizations
relation in theManager
class?I would expect there to be a
has_groups
method available for group members.The text was updated successfully, but these errors were encountered: