Ruby on Rails and database associations

Posted by Marco on Stack Overflow See other posts from Stack Overflow or by Marco
Published on 2010-05-16T17:14:50Z Indexed on 2010/05/16 17:20 UTC
Read the original article Hit count: 220

Hi to all,

I'm new to the Ruby world, and there is something unclear to me in defining associations between models. The question is: where is the association saved?

For example, if i create a Customer model by executing:

generate model Customer name:string age:integer

and then i create an Order model

generate model Order description:text quantity:integer

and then i set the association in the following way:

class Customer < ActiveRecord::Base
  has_many :orders
end

class Order < ActiveRecord::Base
  belongs_to :customer
end

I think here is missing something, for example the foreign key between the two entities. How does it handle the associations created with the keywords "has_many" and "belongs_to" ?

Thanks

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about database