On Tuesday, July 31, 2018 at 5:23:25 AM UTC-7, Paweł Świątkowski wrote:
>
> I came across quite unexpected behaviour of Sequel today. In short:
>
> When I first use graph and then select_append, everything works correctly:
>
> DB[:profiles].graph(:consents, member_id:
> :member_id).select_append(Sequel.lit('m').as(:letter))
> => #<Sequel::Postgres::Dataset: "SELECT \"profiles\".\"id\",
> \"profiles\".\"member_id\", [...] \"consents\".\"member_id\" AS
> \"consents_member_id\", m AS \"letter\" FROM \"profiles\" LEFT OUTER JOIN
> \"consents\" ON (\"consents\".\"member_id\" = \"profiles\".\"member_id\")">
>
> However, when order is different, it throws an error:
>
> DB[:profiles].select_append(Sequel.lit('m').as(:letter)).graph(:consents,
> member_id: :member_id)
> Sequel::Error: can't figure out alias to use for graphing for
> #<Sequel::LiteralString "*">
> from
> /Users/pawel/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/sequel-5.1.0/lib/sequel/dataset/graph.rb:145:in
>
> `block in graph'
> from
> /Users/pawel/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/sequel-5.1.0/lib/sequel/dataset/graph.rb:144:in
>
> `map'
> from
> /Users/pawel/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/sequel-5.1.0/lib/sequel/dataset/graph.rb:144:in
>
> `graph'
> from (irb):6
> from /Users/pawel/.rbenv/versions/2.4.2/bin/irb:11:in `<main>'
>
> This is because #<Sequel::LiteralString "*"> does not meet any conditions
> from case here in _has_key_symbol method:
> https://github.com/jeremyevans/sequel/blob/2622077e57ac884538b2bd3bbae3d2ff6b02adb9/lib/sequel/dataset/actions.rb#L1106
>
> Is this a correct behaviour? Should order matter in this case?
>
Yes, this behavior is expected. Dataset#graph respects existing orders,
but it can't handle the wildcard selection.
There are cases where order does not matter in Sequel, and cases where it
does. Consider:
* select_append.select vs select.select_append
* order.order_append vs order_append.order
* where.or vs or.where
Note that you should not use select_append when using graph. Instead, you
should use add_graph_aliases after graph, so Sequel knows how to handle the
returned values.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.