ok the models look like this: class User < ActiveRecord::Base has_one :address class Address < ActiveRecord::Base belongs_to :user and my tables: users has has the normal id field.. and the addresses has user_id. do I need a foriegn_key statement? also the AR docs say the user_id should be automagicly populated.. if I have an account.. and I''m logged in and create an address... should it not get the user_id populated? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> do I need a foriegn_key statement?No, this is pretty rare. This is usually for odd joins or for legacy table layouts.> also the AR docs say the user_id should be automagicly populated.. > if I have an account.. and I''m logged in and create an address... > should it not get the user_id populated?If you create a new user via some_address.user.new() or some_address.user.create() then everything will be linked together. Easy as pie eh? -Chuck Vose www.chuckvose.com --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ok I''m a newbie and a newbie to OO programming!!!
here is what i got..
1) the user creates an account via the restful_authentication gem
2) i have created a table addresses with a user_id field
3) setup the belongs_to has_one relationship
4) after the user autherizes the account they can login and access the
site
5) and complete some forms about them selfs address etc...
what do i need to change when the address get saved to have it get
linked to the account
@address = Address.new(params[:address])
On Jan 4, 6:44 pm, "Chuck Vose"
<vose...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> > do I need a foriegn_key statement?
>
> No, this is pretty rare. This is usually for odd joins or for legacy
> table layouts.
>
> > also the AR docs say the user_id should be automagicly populated..
> > if I have an account.. and I''m logged in and create an
address...
> > should it not get the user_id populated?
>
> If you create a new user via some_address.user.new() or
> some_address.user.create() then everything will be linked together.
>
> Easy as pie eh?
>
> -Chuck Vosewww.chuckvose.com
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---