On Apr 13, 12:01 am, Paul Jonathan Thompson <[email protected]>
wrote:
> Thanks Anthony,
>
> Did a little more homework and decided to use:
>
> unless @client.line_items.blank?
>
> as .blank? will not bomb on a nil condition and .empty? will.
>

Not sure why you'd want to do that - if a has_many is returning nil
(rather than an empty array) something has gone terribly, terribly
wrong. Also, .blank? isn't proxied like .empty? is - blank? will load
the association then call the method; empty? is defined in
AssociationCollection to do a direct SQL query if the association
isn't loaded, potentially skipping a bunch of unneeded object
creation.

Certainly not a big deal, but worth following the standard API for
efficiency's sake.

--Matt Jones

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