Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

I've added a couple of lines into the Readme to explain how to select multiple attributes #264

Merged
merged 2 commits into from

4 participants

@peternixey

It took me a little while to figure out how to select multiple attributes in a query. I've added little paragraph in which details this

@peternixey peternixey Added instructions for how to select multiple attributes in Squeel
It took me a little while to figure out how to select multiple attributes in a query. I've added little paragraph in which details this
417f008
@the8472

btw, passing an array of keypaths works too .select{[foo,bar]}

@ernie
Owner
@peternixey

Thank you - I didn't realise that - have updated it.

@ernie ernie merged commit 20eb0fa into activerecord-hackery:master
@MrSnot

@peternixey Why would you not just use:
p = Person.select{[name.op('||', '-diddly').as(flanderized_name), coalesce(name, '').as(name_with_default)]}.first

Would this not accomplish the same thing you are trying to do? As separate scopes, it is possible to chain them, but I'm not sure what this example offers.

@MrSnot

Sorry resolved almost 3 weeks ago... :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 1, 2013
  1. @peternixey

    Added instructions for how to select multiple attributes in Squeel

    peternixey authored
    It took me a little while to figure out how to select multiple attributes in a query. I've added little paragraph in which details this
  2. @peternixey
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 0 deletions.
  1. +12 −0 README.md
View
12 README.md
@@ -467,6 +467,18 @@ p.flanderized_name
As you can see, just like functions, these operations can be given aliases.
+To select more than one attribute (or calculated attribute) simply put them into an array:
+
+```ruby
+p = Person.select{[ name.op('||', '-diddly').as(flanderized_name),
+ coalesce(name, '<no name given>').as(name_with_default) ]}.first
+p.flanderized_name
+# => "Aric Smith-diddly"
+p.name_with_default
+# => "Aric Smith"
+```
+
+
## Compatibility with Active Record
Most of the new functionality provided by Squeel is accessed with the new block-style `where{}`
Something went wrong with that request. Please try again.