문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top