I have something like that: class Commercial < ActiveRecord::Base belongs_to :announcer has_many :tags, :as=> :taggable end class Announcer < ActiveRecord::Base has_many :commercials has_many :tags, :as=> :taggable end class Tag < ActiveRecord::Base belongs_to :taggable, :polymorphic => true end with commercials (id,name) announcers(id,name) tags(id,name,taggable_id,taggable_type) now that''s not very DRY because I have several tags that repeat themselves for different taggable_type. is there a better way to deal with that? thanx in advance Pat --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You could turn tags into an intermediate join table on a "tag details" class -- although after typing it out it looks pretty ugly. You don''t save that much unless your name column is going to be huge or unless you''re going to store more information per tag (e.g. create date, counter caches etc). Schema: tags(id, taggable_id, taggable_type) tag_details(tag_id, name) class Tag < ActiveRecord::Base belongs_to :taggable, :polymorphic => true has_one :tag_detail, :dependent => :destroy def name tag_detail.name end def name=(v) tag_detail.name = v end def ensure_tag_detail create_tag_detail end after_validation_on_create :ensure_tag_detail end class TagDetail < ActiveRecord::Base belongs_to :tag end On May 3, 6:27 am, "Patrick Aljord" <patc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have something like that: > > class Commercial < ActiveRecord::Base > belongs_to :announcer > has_many :tags, :as=> :taggable > end > > class Announcer < ActiveRecord::Base > has_many :commercials > has_many :tags, :as=> :taggable > end > > class Tag < ActiveRecord::Base > belongs_to :taggable, :polymorphic => true > end > > with commercials (id,name) > announcers(id,name) > tags(id,name,taggable_id,taggable_type) > > now that''s not very DRY because I have several tags that repeat > themselves for different taggable_type. > is there a better way to deal with that? > > thanx in advance > > Pat--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ok thanx, I think I''ll stay with the first simple polymorphism solution. On 5/3/07, eden li <eden.li-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > You could turn tags into an intermediate join table on a "tag details" > class -- although after typing it out it looks pretty ugly. You don''t > save that much unless your name column is going to be huge or unless > you''re going to store more information per tag (e.g. create date, > counter caches etc). > > Schema: > tags(id, taggable_id, taggable_type) > tag_details(tag_id, name) > > class Tag < ActiveRecord::Base > belongs_to :taggable, :polymorphic => true > has_one :tag_detail, :dependent => :destroy > > def name > tag_detail.name > end > > def name=(v) > tag_detail.name = v > end > > def ensure_tag_detail > create_tag_detail > end > after_validation_on_create :ensure_tag_detail > end > > class TagDetail < ActiveRecord::Base > belongs_to :tag > end > > On May 3, 6:27 am, "Patrick Aljord" <patc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I have something like that: > > > > class Commercial < ActiveRecord::Base > > belongs_to :announcer > > has_many :tags, :as=> :taggable > > end > > > > class Announcer < ActiveRecord::Base > > has_many :commercials > > has_many :tags, :as=> :taggable > > end > > > > class Tag < ActiveRecord::Base > > belongs_to :taggable, :polymorphic => true > > end > > > > with commercials (id,name) > > announcers(id,name) > > tags(id,name,taggable_id,taggable_type) > > > > now that''s not very DRY because I have several tags that repeat > > themselves for different taggable_type. > > is there a better way to deal with that? > > > > thanx in advance > > > > Pat > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---