On Tue, Oct 11, 2011 at 7:38 PM, Nikhil Goyal <[email protected]>wrote:

> I had setup the associations, one to one, because that was the
> requirement
>
> User Model
> has_one :referral
>
> Referral Model
> belongs_to :user
>
> and I also setup a "user_id" column in Referral model.
>
> But what I did not know was about the magic call "BUILD"
>
> Now I guess, all I have to do is
>
> @user = User.new(:params[:user])
> @user.referral.build
> @user.save
>

Hi Nikhil,

A few hints.

* there is a preference (at least by me) to reply below the previous text
  as I do here (as opposed to "top quoting")
* you can find all details about these association methods in section
  "4.2 has_one Association Reference" of
http://guides.rubyonrails.org/association_basics.html
* actually, I believe what you propose above will not work, it would
probably be

 @user.build_referral # untested

HTH,

Peter

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to