Need some brainstorming help: acts_as_taggable_list?


#1

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 :slight_smile:


#2

To avoid confusion, in my previous post I used the term “message” and
“item” to mean the same thing - sorry about that. Thought “items” would
be clearer, but in my actual app the model is a “message” so I slipped.
:slight_smile:


#3

Update: I’m leaning toward a model that adds a TagList object that just
has a user_id and a Tagging… so another table, but without the column
duplication. Right now I’m thinking I may still be able to use
acts_as_taggable with this model, but I’m still fleshing it out.