Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Cannot destroy object if the model has default_scope with reference to another table #111

Closed
mitoyarzun opened this issue May 10, 2013 · 2 comments

Comments

@mitoyarzun
Copy link

How to reproduce:

class Parent < ActiveRecord::Base
  acts_as_paranoid
  has_many :children
end

class Child < ActiveRecord::Base
  belongs_to :parent
  acts_as_paranoid
  default_scope includes(:parent).order('parents.position DESC')
end

When you try to destroy a Child, it can't because the default scope is not called:

ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'parents.position' in 'order clause': UPDATE `children` SET deleted_at = '2013-05-10 15:41:09' WHERE `children`.`id` = 5 ORDER BY parents.position ASC

Can anyone reproduce it?

Thanks.

@alexisraca
Copy link

  • 1 to this, error on PG, it says the refference does not exist when it tries to reorder, is there a workaround?

@zzak
Copy link
Contributor

zzak commented May 12, 2014

I think this is a duplicate of #62

@zzak zzak closed this as completed May 12, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants