I’m trying to figure out the best way to set this data model up. I’m
still
pretty new to Rails, but hopefully I could turn this into something
useful
to others as well. Here are the basics:
User has_many items
items are taggable (items habtm taggings, tags habtm taggings)
I also want users to be able to order their tagged items. So if I’ve
tagged 5 items as “cool” I want to be able to order them 1-5.
The DB design seems straight forward:
items:
id
user_id
name, etc
tags:
id
name
taggings:
tag_id
message_id
position
But it gets hairy when trying to use ActiveRecord relationships. There
are
some good ideas about HABTM lists:
http://wiki.rubyonrails.org/rails/pages/HowToUseActsAsListWithHasAndBelongsToMany
But easily getting that to only show messages for a particular user is
not
straightforward. You could hack it a bit by adding another table/model
that
was a TagList, with a user_id, tag_id, message_id, and position - but
that
seems like a lot of data duplication.
That just got me thinking that maybe you can make the model for TagList,
but
not have it be based on an actual table (make it a composite model). I
seem
to remember reading about that - maybe I’m delirious - I’m off to look
it
up.
Anyone have any thoughts on this? And please don’t tell me there is
some
better support for this in Edge Rails. I’ve tried getting Edge Rails
running, and it has broken me. I’ll wait until 1.1 is out