On 13 July 2012 02:23, Jean-Sébastien D. <li...@ruby-forum.com> wrote:
> Colin Law wrote in post #1068473:
>> On 12 July 2012 17:56, Jean-Sbastien D. <li...@ruby-forum.com> wrote:
>>>> Can you explain the above again, I don't understand what you are
>>> CUSTOMER                     ORDER
>>>
>>> CUSTOMER                      ORDER
>>> first_name                    price
>>> last_name                     proceed_at
>>> password
>>> emails
>>>
>>> Now in models I would have to say
>>>
>>> Customer belongs to order
>>> Order has customer
>>
>> I think that should be customer has_many orders and order belongs_to
>> customer.  The words make some reasonable sense in english.
>>
>>>
>>> Now my main questions I understand I dont define customer_id and
>>> order_id in customer and order table because its already assume to have
>>> an id key when created. But in ORDER model should I define
>>> customer_id:integer and in model say
>>> ORder customer_id: has customer. To let it know that this field is
>>> actually a foreign key?
>>
>> Since order belongs_to customer then the orders table (note the plural
>> name for the table) should have a customer_id column.  You don't need
>> to tell rails that it is a foreign key, it will know that from the
>> model relationships.  To specify it in the migration for orders you
>> can say (as is mentioned in the migrations guide).
>>
>>   t.references :customer
>> or
>>   t.integer :customer_id
>>
>> As I think I said previously if you work right through some tutorials
>> all this should become clear.
>>
>> Colin
>
> Sorry here a question in term of modeling!! BTW thanks I am learning a
> lots with your comments
>
> But I just want to make sure I get the association concept understood
> well. I place a question few days ago on this links
> http://railsforum.com/viewtopic.php?pid=153916#p153916 but don't seem to
> have quick Answer. I just wanna make sure I understand the concept of
> association compared to php

It is no good just posting a link to a thread that appears to have
already been answered.  If you have a specific still unanswered
question then post it here.  However as I have said twice before you
really should work through some tutorials to get the basics rather
than asking such questions here.  Once you have done that the answers
will mostly become obvious to you.

Colin

-- 
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-US.

Reply via email to