groupify
groupify copied to clipboard
Passing a block of extensions to groupify generated associations
Given the models in active_record_spec I would like to:
class User < ActiveRecord::Base
groupify :group_member do
def some_operation_on_the_association
proxy_association.owner.something
end
end
end
to end up as if I had defined the association with the block:
class User < ActiveRecord::Base
has_many :groups, { ... } do
def some_operation_on_the_association
proxy_association.owner.something
end
end
end
This should not interfere with the pre-existing extend: GroupAssociationExtensions
style options defined in the associations.
Does this feature seem feasible? I did not create a commit yet due to multiple directly related open branches.
It's reasonable to want more control over the auto generated associations. Similar idea as #50.
The implementation you suggested is feasible for the groups
association because only one is generated. Over on the groups side, multiple member associations can be created, and each one may need to be customized differently. Maybe this can be accomplished by calling has_member
multiple times, one for each member association.
@juhazi I sent you an invitation to give you collaborator access (which gives you push rights to the repo). Feel free to play around with your ideas in a branch and open a PR when you think it's ready.
Thank you for the access.
Started work in 9b87bed
If it looks ok I'll replicate it for all relations.