开发者

How do you use ARel's #as method?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜