Please disregard.
Not enough sleep.
I have figured out the problem.
My relationships were backwards.
Should have been products belongs_to supplier and supplier has_many
products.
Sorry,
~d
_____
From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On
Behalf Of Damon Hill
Sent: Sunday, October 16, 2005 12:05 PM
To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails] One to One relation questions :=> newb
Ok, I am a little confused right now regarding the has_one and belongs_to
relationships.
I have the following relationships established:
A product can contain only one supplier.
Therefore, product.rb has the has_one :supplier.
The supplier.rb has the belongs_to :product.
There is a foreign key relationship between the supplier_id column in the
products table to the id column in the suppliers table.
However in my view when executing the following:
product.supplier.company_name
Rails attempts to execute this sql statement:
SELECT * FROM suppliers WHERE supplier.products_id = 2
The problem there is that there is no products_id column in the supplier
table.
I would have expected the following sql statement to execute:
SELECT company_name FROM suppliers WHERE id = ''3'';
Can someone explain the relationships a little better to me and why I am not
getting the sql statement I expected?
Thanks in advance for the help and insight.
M Damon Hill
Project Manager
IFWORLD, Inc.
www.ifworld.com <http://www.ifworld.com/>
"..as we''re sung to sleep by philosophies that sing save the trees
and kill
the children...." -- while you were sleeping (casting crowns)
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails