Arun Srini wrote in post #955342:
>
> class CreateRoomtypes < ActiveRecord::Migration
>     create_table :roomtypes do |t|
>       t.string :t_name
>       t.string :rate
>       t.string :comment
>       t.timestamps
>     end
> end
> class CreateRooms < ActiveRecord::Migration
>     create_table :rooms do |t|
>       t.string :name
>       t.boolean :avail
>       t.string :type_name  - to reference Roomtype's name
>
>       t.timestamps
>     end
>   end
>
> I want to use type_name column of Rooms as foreign key to Roomtype
> model. I tried running below queries but in vein. What am I doing
> wrong? How to 'plumb these together'?
>

Since you do seem to be defining the rooms table, why not use the rails 
'traditional' roomtypes_id field as your key?  It is much clearer (I 
know what that field is, and I know where it connects to), it is the 
'convention over configuration' solution, and it alleviates any 
potential issue with someone in the future deciding that "Oh, that room 
type name doesn't really fit anymore, can I change it?" - I personally 
abhor descriptive strings as keys for precisely that reason...

Leave some of that DB world training behind and embrace the 'rails way', 
you'll be much happier, and things tend to fit more naturally.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to