The associations you create in a model have to be backed up by the 
appropriate fields in the DB.

For example:

class Person
  has_many :addresses

class Address
  belongs_to :person

should be a model representation of the relationship inherent in the 
database (the two really go hand-in-hand).

if:

Table people
  id:integer
  first_name:string
  last_name:string

Table address
  id:integer
  person_id:integer
  line1:string
  line2:string
  city:string
  state:string
  postal_code:string

has_many :addresses tells Rails that for a given person, it can use that 
person id field to retrieve address records (those whose person_id 
matches the current person id value). Similarly, from an address, Rails 
can get back to the person record by following the person_id on the 
address.

-- 
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-talk@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