On Jan 8, 5:20 pm, Frederick Cheung <[email protected]>
wrote:
> On Jan 7, 5:03 pm, IAmNan <[email protected]> wrote:> At the point
>
> > If I stop in the debugger at
> >   self.buyer_id = self.buyer.id # Won't work without this line, seems
> > un-DRY or worse
>
> I'd try stepping through the assignment in self.buyer = foo. In theory
> you should end up in BelongsToProxy#replace which in turn should be
> setting buyer_id

Shouldn't this happen only after you save the initial object?
I mean that at the time you do self.buyer = User.create ... it creates
a new associated object in the memory as an attribute of self, but
buyer_id still doesn't have that information because at the time you
fetched a self object into the memory it just didn't exist.
I think if you do self.save (in your example it should be only for
testing purposes because it's already inside the save callback) and
self.reload after self.buyer = User.create you should see a value
assigned.
--
Thanks, Ivan Povalyukhin

> Fred
>
>
>
>
>
>
>
> > Then...
> >   self.buyer has a valid :id
> >   self.buyer_id is nil
>
> > On Jan 7, 12:34 pm, Frederick Cheung <[email protected]>
> > wrote:
>
> > > On Jan 7, 4:04 pm, IAmNan <[email protected]> wrote:
>
> > > > ordered_by is the email address on the order#form. You'll notice buyer
> > > > shares the table with user. To head off questions about
> > > > find_or_create_by, I have other things do to the new user where you
> > > > see snip, and it also results in the user being created but the
> > > > buyer_id is not set.
>
> > > What's the value of self.buyer_id before you force it ?
>
> > > Fred

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