groupify icon indicating copy to clipboard operation
groupify copied to clipboard

Passing a block of extensions to groupify generated associations

Open juhazi opened this issue 8 years ago • 4 comments

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.

juhazi avatar Jun 16 '16 17:06 juhazi

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.

dwbutler avatar Jun 17 '16 03:06 dwbutler

@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.

dwbutler avatar Jun 18 '16 07:06 dwbutler

Thank you for the access.

juhazi avatar Jun 27 '16 10:06 juhazi

Started work in 9b87bed

If it looks ok I'll replicate it for all relations.

juhazi avatar Jul 03 '16 14:07 juhazi