You''re on the right track. Look at the polymorphic associations
described in: http://api.rubyonrails.org/classes/ActiveRecord/
Associations/ClassMethods.html
It was something like this that I figured out how to do in 1.0 about
a week before 1.1 introduced polymorphic associations.
-Rob
Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
On Jul 7, 2006, at 8:33 PM, Jason Frankovitz wrote:
> I''m using a db to log two types of events, link events and tag
> events. At first I had two tables, link_events & tag_events, but
> this seemed not very DRY because the only column that was different
> between them was link_id and tag_id respectively. So I made these
> tables:
>
> events:
> id int
> user_id int
> objtype_id int (holds ''1'' or ''2''
depending on if the item is a link
> or a tag)
> lort_id int ("link or tag id" == "lort" this holds the
id of the
> item involved in the event)
>
> objtypes: (only has two records {1 => link, 2 => tag})
> id int
> name int
>
> links:
> id int
> url string
>
> tags:
> id int
> name string
>
> What I can''t figure out is how to tell the Event model that
lort_id
> belongs_to links if the value is 1, and that it belongs_to tags if
> the value is 2. Is this possible/wise/insane?
>
> Thanks in advance!
> -Jason
> --
> Jason Frankovitz - jason@seethroo.us - http://www.seethroo.us/
> work: (310) 601-8454
> cell: (415) 254-4890
> AIM/Skype: jfrankov
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060708/90977950/attachment.html