[AWDwR] Confused about has_one and has_many

Heya everyone! I am quite new to Rails and I am reading AWDwR. I am at Task E "Check Out!". I understand it quite well, but I have a problem with the last playground exercise: Add a Table which contains the payment types. All goes well, but I am not sure whether I should use has_many or has_one(as in the Playground wiki at Pragmatic Bookshelf: By Developers, For Developers).

I use the following:

class Order < ActiveRecord::Base   belongs_to :pay_type   ... end

and

class PayType < ActiveRecord::Base   has_many :orders   ... end

Is this right? Or should I use has_one instead of belongs_to in Order? An order references to one PayType, Order has one PayType. I am confused, please help me.

Regards, Thomas

Heya everyone! I am quite new to Rails and I am reading AWDwR. I am at Task E "Check Out!". I understand it quite well, but I have a problem with the last playground exercise: Add a Table which contains the payment types. All goes well, but I am not sure whether I should use has_many or has_one(as in the Playground wiki at Pragmatic Bookshelf: By Developers, For Developers).

Or should I use has_one instead of belongs_to in Order? An order references to one PayType, Order has one PayType. I am confused, please help me.

This might be useful to help illustrate things...

http://mboffin.com/stuff/ruby-on-rails-data-relationships.png

Ah! Thank you! So just to make it clear: An Order belongs_to a PayType because the Orders table has an pay_type_id. And PayType has_many Orders because, many Orders reference to the pay_types table. Right?

Seems right yeah.

Thank you Philip!