views:

237

answers:

1

Hi!

I'm building a "small" personal web app in Ruby on Rails. I've set it up so that I'm using a MySQL database.

The idea is that I'm gonna store and navigate many kinds of data (notes, bookmarks, movie and appliction ratings) with this app. I want to index/categorise this data in a pseudo-directory structure. (The directory structure exists only in the database - not in actual directories)

E.g. a bookmark could be stored in Root -> Bookmark -> Funny -> Keyboard cat

Now I've seen this question but I don't now whether that solution is the best way to do it in a rails app. A solution similar to the one in the question I linked to above was also what I had in mind. But one could also add an extra table having the relations between folders and their content.

The question is how do I structure my models and my database? (The "right" way)

Update: (@Dave and other taggers) Yes, I've thought about tags. And at first I was actually going to ask a much larger question but I was unable to do so in a concise way. The deal is that it's also going to be possible to tag items. And in reality the directories ARE tags - you could say I want to have two ways of organising things - 'structured' tags (directories) and 'free' tags (your old regular tags). But that's a whole different story...

For now I just wanna see the "right" way of doing the rails model and the database structure for the directory problem.

A: 

It sounds like you'd want a series of one-to-many relationships, if it's truly mimicking a directory structure. E.g. pictures (like 'keyboard cat') can belong to only one category (like 'funny'), while each category can have many pictures.

However, you may want to rethink the directory structure & opt for something more flexible, like tags. Because if 'keyboard cat' could belong to more than just 'Funny', it would break the one-to-many relationships that defines a standard directory-like structure.

fig