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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D49e8a6c0c80817c34d9a5bc74c72cbc?d=identicon&s=25 Chris Rericha (tristipher)
on 2007-01-28 22: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,
I've
noticed that I have a good amount of duplicate functionality within
these
classes for the Note interface.  I would like to move this functionality
as
well as the actual has_many :through and join table associations into
one
common file in order to adhere to the DRY principle.

I tried to make my classes inherit from a NoteInterface class that
contained
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.
Is
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,
but
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?

Thanks!
Chris
This topic is locked and can not be replied to.