views:

93

answers:

2

I'm starting to spec out an image gallery type system similar to Facebook's. Members of the site will be able to create image galleries and upload images for others to view. Images will have keywords the the uploader can specify.

Here's the question, what's the best way to model this? With image and keyword tables linked vi a HABTM relation? Or a single image table with the keywords saved as comma delimited values in a text field in the image record? Then search them using a LIKE or FULL TEXT index function?

I want to be able to pull up all images containing a given keyword as well as generate a keyword cloud.

I'm leaning toward the HABTM setup but I wanted to see what everyone else though. Thanks!!

+4  A: 

I'd highly suggest a HABTM relationship. IMHO, storing multiple fields in one column (e.g. comma delimited tags) is a terrible idea... Think of the nightmare you'll have in searching multiple tags, or if the keywords were input in the wrong order! Also, generating a keyword cloud would be nigh impossible if you don't have a keywords table.

So yea, I guess that's my 2 cents :D

Jeriko
+1 Because of the nightmare factor. HABTM all the way.
Rob Wilkerson
A: 

Have a look at the gallery phtagr which targets similar mentioned features. phTagr is an open source social web gallery with a cool group based access management. Photos can be tagged with keywords, categories, or locations (and yes, it uses HABTM relations for it). You can also create your selection based on any keyword, category, or location and can even exclude them. It has also tag clouds, user comments, RSS, MediaRSS and a buildin slideshow.

xemle