On 17 November 2010 01:09, arga aridarma <arga_arida...@yahoo.com> wrote:
> ----- Original Message ----
>
> From: Colin Law <clan...@googlemail.com>
> To: rubyonrails-talk@googlegroups.com
> Sent: Wednesday, November 17, 2010 5:29:48
> Subject: Re: [Rails] Re: Re: Why is my models can't be related using has_one 
> and
> belongs_to?
>
> On 16 November 2010 22:03, arga aridarma <arga_arida...@yahoo.com> wrote:
>
>> Please don't top post, it makes it difficult to follow the thread
> Sorry.
>
>>I asked what happens when you execute
>>@user = ComUser.find(:first)
>>@a = @user.def_jabatan.jabatan
>
> ok, by executing this, the debug of @user returns the ComUser object and also
> the related DefJabatan object. So it seems that i have to "access" the
> relationship manually rather than expecting that @user = ComUser.find(:first)
> will return the whole objects package, including all the related object. Am I
> correct?

Without the include ComUser.find fetches just the ComUser object.
When you then access @user.def_jabatan Rails realises that the
DefJabatan object has not been read and so goes and gets it.  It is
not that you have to access the relationship manually in order to
fetch it, it is that _if_ you access it then it will fetch it.
Normally this is appropriate as it only fetches stuff that is
required.

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-t...@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.

Reply via email to