Forum: Ruby on Rails Avoiding duplication in Has Many :through polymorphic associ

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Chris R. (Guest)
on 2007-01-28 23:42
(Received via mailing list)
Hi everyone,

I have a group of classes that I associate to a Note class through a
has_many :through polymorphic association, which works great!  However,
noticed that I have a good amount of duplicate functionality within
classes for the Note interface.  I would like to move this functionality
well as the actual has_many :through and join table associations into
common file in order to adhere to the DRY principle.

I tried to make my classes inherit from a NoteInterface class that
the associations, but the association would use the parent class
(NoteInterface) as the type in the join table.  I already had to use
set_table() to get AR to use the name of the child class for the table.
there a similar way to override the name of the type a polymorphic
association will use?

I also tried putting the associations in a module and use it as a mixin,
when ruby parses the file, it doesn't know what to do with them.

Has anyone else tried to do this?  Is this even be possible?

This topic is locked and can not be replied to.