My Miniature model has the following association:
class Miniature < ActiveRecord::Base
has_many :minilines, dependent: :destroy
has_many :lines, :through => :mini lines
This works fine but I wanted to have the Minilines sorted alphabetically by name so I added this:
class Miniline < ActiveRecord::Base
default_scope { order('name ASC') }
belongs_to :miniature
belongs_to :line
I thought that was working fine but when you come to delete a Miniature you get an error:
ActiveRecord::StatementInvalid (SQLite3::SQLException: no such column: name: SELECT "minilines".* FROM "minilines" WHERE "minilines"."miniature_id" = ? ORDER BY name ASC):
app/controllers/miniatures_controller.rb:205:in `destroy'
Removing the default_scope line allows you to delete the Miniature and has the correct behaviour.
It's not clear to me why the default_scope breaks this behaviour or how to rectify it.
My question appears to be duplicate of this but the ticked solution there doesn't solve it for me.