Topic: Can I do this with rails models? Own table for Category, without ID

So, can I do this: (as correct database convention is setup to not get redundancy for the category table)

One model for Movie that has, for example these fields:
t.string "Title"
t.integer "Year"
t.text "Description"
And then one index that links to the Genre-table in a many-to-many-relation.

And then another model named Genre with only one field:
t.string "Genre"

This last one pretty much contain static data about the Genres, and requires NO ID, only uniqueness.

Re: Can I do this with rails models? Own table for Category, without ID

You could do it, 
create_table :genres, :id => false do |t|
   t.string :genre
end
class Genre < ActiveRecord::Base
  set_primary_key :genre
end

Although the extra cost of a simple integer in the table isn't that expensive,  and I'd be willing to bet at some point you'd design yourself into a corner and regret doing it.  For example,  what if you wanted to 'rename' an existing Genre?  All your relationships would have to be re-built!!!!

I would think long and hard before proceeding

Last edited by BradHodges (2012-03-11 14:31:56)

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Can I do this with rails models? Own table for Category, without ID

Thanks!

Yeah I guess, was just a thought about proper relational database usage I thought of.
When renaming I dont really know... It still is referenced by the movie table, so I guess the reference to the changed genre will also change in someway?

Well, I may perhaps just add an ID to the Genre-table. I guess it's less work to do if I would like to allow movies for more than one genre and at the same time be able to search for genre specific movies.