:has_many and :belongs_to: how do they work

I am new to rails, and don’t know how :has many and :belongs to work,
but I really like the idea of being able to say, for example
email.accounts, and I was wonderign what the requirements are. Does this
system work off of foreign keys, or does it work off of a system like
this
for example
email table


email account

Accounts table


name email

meaning, that it matches the two email fieldnames?

Accounts table


name email

meaning, that it matches the two email fieldnames?

By default, ActiveRecord expects foreign keys to be named

_id.
In your example, account would have a field called email_id of type
:integer. You can then use belongs_to and has_many.

I would also suggest you spend some time trawling the web for
tutorials/books. There are many out there and they’ll help you
understand how Rails is put together.

Max

Thanks for your help and time. I am a novice at both rails, and
databases, so sometimes I can code things, but I don 't understand how
they work.

Ben, I highly suggest you get the book Agile Development on Rails, and
read
it. It will give you a good understanding of how Rails works. Without a
good
understanding of the underlying technology, you’ll probably keep running
into walls when coding. But once you understanding it, coding becomes
fairly
simple.

On 8/21/06, Ben [email protected] wrote:


“Impossible is nothing.”