On Jun 29, 2:47 pm, mhayden <[email protected]> wrote:
> The following Sequel code produces a query which seems reasonable and
> produces the data I expect, if I execute it directly as a mysql
> command. However the dataset result gives me some columns with the
> column names inserted where the data should be. These columns happen
> to be those which were disambiguated in a select call.
>
>     qn = Question.table_name
>
>     # get all the questions in reverse chronological order
>     quests_ds =
> Question.dataset.select("#{qn}.id".as(:qid),:question,:background,"#{qn}.created_at").order("#{qn}.created_at").reverse

Sequel is doing what you request, even if it is not doing what you
want.  In Sequel, ruby strings represent SQL strings (quoted with ').
If you want a ruby string to represent SQL code (unquoted), you need
to turn it into a literal string:

 
Question.dataset.select("#{qn}.id".lit.as(:qid),:question,:background,"#{qn}.created_at".lit).order("#{qn}.created_at".lit).reverse

Or better yet, use Sequel's API for qualifying column references.  You
should also note that the select method is defined on Model.  I would
write that part of the query as:

 
Question.select(:id.qualify(qn).as(:qid),:question,:background,:created_at.qualify(qn)).order(:created_at.qualify(qn).desc)

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
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