On Oct 7, 2010, at 10:23 AM, Leonel *-* wrote:

> In my appointments model, I want to order by a column called "when",
> which is supposed to house the appointment date.
> 
> So im my model file appointment.rb I did this...
> 
> class Appointment < ActiveRecord::Base
>  default_scope :order => 'when'
>  [...]
> end
> 
> and I got this error...
> 
> SQLite3::SQLException: near "when": syntax error: SELECT
> "appointments".* FROM       "appointments"  ORDER BY  when
> 
> -----------------------------
> 
> So then I used ticks...
> 
> class Appointment < ActiveRecord::Base
>  default_scope :order => '`when`'
>  [...]
> end
> 
> and it worked. I have something similar with my client.rb file, didn't
> used ticks and never had any problem.
> 
> class Client < ActiveRecord::Base
>  # Order clients alphabetically
>  default_scope :order => 'name'
>  [...]
> end
> 
> Is there a reason for this error? is "when" a reserved keyword? I
> googled "sqlite3 when" and didn't find anything. Sorry if my question
> may seem irrelevant, it's just that I want to UNDERSTAND Rails.

Yes.  Google for "sqlite reserved words"...

http://www.sqlite.org/lang_keywords.html

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: 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/rubyonrails-talk?hl=en.

Reply via email to