Has_and_belongs_to_many DRY?

Hi,

I have many “has_and_belongs_to_many” that looks nearly the same, I
wonder if I can do anything so I DRY myself? maybe write a plugin? What
do you think?

The lines look like this.

has_and_belongs_to_many :snippets,
:class_name => ‘Container::Snippet’,
:conditions => [ “containers.reference_type =
‘Layout’ AND containers.container_type = ‘Snippet’” ]
:join_table => :containers,
:foreign_key => :reference_id,
:association_foreign_key => :container_id

has_and_belongs_to_many :modules,
:class_name => ‘Container::Module’,
:conditions => [ “containers.reference_type =
‘Layout’ AND containers.container_type = ‘Module’” ]
:join_table => :containers,
:foreign_key => :reference_id,
:association_foreign_key => :container_id

has_and_belongs_to_many :texts,
:class_name => ‘Container::Text’,
:conditions => [ “containers.reference_type =
‘Layout’ AND containers.container_type = ‘Text’” ]
:join_table => :containers,
:foreign_key => :reference_id,
:association_foreign_key => :container_id

Hope someone have a solution, thanks for help :slight_smile:

Regards,
Jamal

I just did simple plugin for this :slight_smile:

Thanks anyway :smiley: