I am new with rails and trying to understand its :has_many and :belongs_to functionalities.
If I have 3 tables: Customers
, Physicians
, Addresses
Each customer and each physician will have one address. So it is a one-to-one relationship.
customer_id and physician_id will match address_id
So if I want address of a customer with id 3. I'd say
select * from customer, addresses
where customer_id = 3 and customer.customer_id = addresses.address_id
How will I translate this into rails code?
I'll have 3 models Customer
, Physician
, Address
But I am not sure as to what the relationship be?
How will i translate the above query to rails find
function?
Customer.find (:all, ......?