Ruby on Rails and database associations
- by Marco
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