How do you use the ARel #as method?

If you build a projection like this:

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

How to get result column named: snark?

+4
source share
1 answer

Since you use Arel Core and inactive recording (which will be preferable in the future), you should understand what happens behind the engine. Depending on whether you call .each or .first, you will be returned an array from Arel :: Row (s) or one Arel :: Row (respectively)

The Arel :: Row consists of at least three parts. Attitude, title and 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 

Greetings

+5
source

Source: https://habr.com/ru/post/1306171/


All Articles