Skip to content

Instantly share code, notes, and snippets.

@stimms
Created October 2, 2014 20:26
Show Gist options
  • Save stimms/35951b118209b2e8ef88 to your computer and use it in GitHub Desktop.
Save stimms/35951b118209b2e8ef88 to your computer and use it in GitHub Desktop.
if(customers != null)
if(customers.Count() > 0)
if(customers.FirstOrDefault().Orders != null)
if(customers.FirstOrDefault().Orders.Count() >0)
if(customers.FirstOrDefault().Orders.First().Address != null)
return customers.FirstOrDefault().Orders.First().Address.First.Zip;
@thescientician
Copy link

Orders.find_by(customer: customer).try(:address) || "No Address"

@thescientician
Copy link

Eh... You can code around it, most of this is just sugar on top of .limit(1) calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment