rails / arel

A Relational Algebra
2.06k stars 390 forks source link

NamedFunction as #535

Closed YarikST closed 6 years ago

YarikST commented 6 years ago

It would be nice if as created a new object and did not change the existing one

2.4.0 :037 > f = Arel::Nodes::NamedFunction.new('ts_rank_cd', [0])
 => #<Arel::Nodes::NamedFunction:0x007ff8de2790c8 @expressions=[0], @alias=nil, @distinct=false, @name="ts_rank_cd"> 
2.4.0 :038 > f2 = f.as('123')
 => #<Arel::Nodes::NamedFunction:0x007ff8de2790c8 @expressions=[0], @alias="123", @distinct=false, @name="ts_rank_cd"> 
2.4.0 :039 > f
 => #<Arel::Nodes::NamedFunction:0x007ff8de2790c8 @expressions=[0], @alias="123", @distinct=false, @name="ts_rank_cd"> 
2.4.0 :040 > f2
 => #<Arel::Nodes::NamedFunction:0x007ff8de2790c8 @expressions=[0], @alias="123", @distinct=false, @name="ts_rank_cd"> 

This behavior works on tables

t1 = table
t2 = t1.as('123')
t1 != t2

In the end, you need to add to select and order, I would write the function and in select give as a and in order it is not required - and in the current implementation, I need two functions one of the same friend without

rafaelfranca commented 6 years ago

Per #523, Arel development is moving to rails/rails.

If this issue is still relevant, please consider reopening it over there. (Note that the Rails repository does not accept feature request issues, and requires reproduction steps that rely on Active Record's documented API.)

YarikST commented 6 years ago

Thank you very much for the answer