On Wednesday, December 19, 2012 12:29:41 PM UTC-8, Geraldo Lopes de Souza 
wrote:
>
> Thank you Jeremy. 
>
> I'm playing with dataset syntax to choose which one to use. 
>
> I rewrote as: 
>
> ds = DB[:employees___employee].select(:first_name, :last_name, 
> Sequel::SQL::Function.new('upper', 
> :last_name).as(:upper_last_name)).graph(:employees, 
> {:employee_id => :manager_id}, {:table_alias => :manager, :select => 
> [:first_name  ]}) 
>

This is a fine way to do that. 
 

> If you use set_graph_aliases to select which fields you want kind of 
> defeats the advantage of the graph that is no need to alias 
> everything. 
>

Correct.  set_graph_aliases should only be used in cases where you need a 
lot of control over the graph.  In most cases, you can use Dataset#select 
and the :select option for the parts that they handle, and 
add_graph_aliases for the other parts.

Originally, you could not do what you are doing now, and 
set_graph_aliases/add_graph_aliases was necessary for advanced cases.  Now, 
in some cases graph's :select option can be used instead of 
*_graph_aliases.  However, not in all cases.  For example, if you wanted to 
run the upper function on manager.first_name, you couldn't use :select to 
do that.  You would need to do:

ds = DB[:employees___employee].
select(:first_name, :last_name, 
Sequel::SQL::Function.new('upper', 
:last_name).as(:upper_last_name)).graph(:employees, 
{:employee_id => :manager_id}, {:table_alias => :manager, :select => 
[]}).add_graph_aliases(:manager_name=>[:manager, :first_name, 
Sequel.function(:upper, :manager__first_name)]) 

Note that I'm using select on the main dataset. and :select option on 
> the graphed one to choose which fields I want. Is that allowed ? 
>
 
Yes.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/B55jZC4Pf3sJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to