Tuesday, December 15, 2009

[Rails] Re: Why not associations without an extra table?

On Dec 15, 7:34 am, Andrew Pace <andrewpp...@gmail.com> wrote:
> Give us more code, because this can be done in a single step.
>
> Chaining method calls like that will return a single department object
> (e.department).  So it should be no different, and I have done similar
> things in the past without trouble.
>
> The only time this shouldn't work is if you try something like
> e.departments.customers.  This is because the plural "departments"
> means you will return multiple departments.  That collection will not
> have a single ".customers" method.


I figured out why is doesn't work and to my great shame, I'd actually
read this article
http://blog.hasmanythrough.com/2008/2/27/count-length-size

In rails, you need to use .count and not .size for this to work
because the first collection has already been loaded and therefore you
are asking for the length and not the count! The length == 0 and so
no records are returned.

--

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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate