views:

190

answers:

1

If you build a projection like this:

t = Arel::Table.new(:projects)
ps = t.project(t[:id].as(:snark))

How do you get the result column that's named :snark?

+1  A: 

Since you are using the Arel Core and not active record (which will be preferred in the future) You must understand what is going on behind the engine. Depending on if you call .each or .first you will be returned an array of Arel::Row(s) or a single Arel::Row (respectively)

The Arel::Row consists of at least three parts. The relation, the header, and the body (tuple). These are the principles of relational algebra.

t = Arel::Table.new(:projects)
ps = t.project(t[:id].as(:snark)).first 
#should do the trick and return an Arel::Row

Cheers

Snuggs