On Friday, August 8, 2014 4:17:42 PM UTC-7, Lin Jen-Shin wrote:
>
> Hi,
>
> I've been wondering why calling `association_join' and
> `select' in different order would matter? For example,
> this does work as expected:
>
> User.association_join(:expertises).
> select{[users.*, count(users__id)]}.
> group_by(:users__id).sql
>
> # => SELECT "users".*, count("users"."id") FROM "users" INNER JOIN
> "expertises" ON ("expertises"."user_id" = "users"."id") GROUP BY
> "users"."id"
>
> But if I change the order of association_join and select,
> it won't work:
>
> User.select{[users.*, count(users__id)]}.
> association_join(:expertises).
> group_by(:users__id).sql
>
> Here's the error:
>
> # => Sequel::Error: can't figure out alias to use for graphing for
> #<Sequel::SQL::ColumnAll @table=>#<Sequel::SQL::Identifier
> @value=>:users>>
>
> If I remove the count in `select', both would work,
> but oddly it would immediately make a query:
>
> User.select{users.*}.
> association_join(:expertises).
> group_by(:users__id).sql
>
> # => SELECT "users".* FROM "users" LIMIT 1
>
> Not that I am only calling `sql', not expecting it
> would make a query at all.
>
> Thanks for any hints.
>
association_join uses eager_graph internally, and eager_graph needs to
determine the aliases that will be used, which it can't do for an unaliased
function call. The error message also shows it can't do it for a wildcard
selection, but I think a pure wildcard selection is special cased (so the
table_select plugin works), though it does apparently do a query for the
columns.
I think it shouldn't be difficult to change things so that it works in
either order and no query for the columns is done. I'll try to make such
changes before the next release.
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 http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.