In Rails 4.0 I have 2 ActiveRecord classes:
class Sequence < ActiveRecord::Base
has_many :steps, dependent: :destroy
end
and
class Steps < ActiveRecord::Base
belongs_to :sequence
default_scope -> { order('order ASC') }
end
When I call mySequence.destroy
I get this error:
PG::SyntaxError: ERROR: syntax error at or near "order" LINE 1: ...steps" WHERE "steps"."sequence_id" = $1 ORDER BY order ASC ^ : SELECT "steps".* FROM "steps" WHERE "steps"."sequence_id" = $1 ORDER BY order ASC
When I remove the default scope, the error is gone, but I obviously have to order the steps in my sequence in my code. I did try to define the association like this, and leaving out the default_scope statement:
class Sequence < ActiveRecord::Base
has_many :steps, dependent: :destroy, order: 'order ASC'
end
but it threw the same error.
Does anyone else have this issue? Is this a bug in Rails? I imagine the ordering is not needed in the destroy sql statement on the children.