Skip to content

Fix issue with default scope clashing with deletion.#70

Merged
radar merged 1 commit into
rubysherpas:masterfrom
heisenbugged:master
Sep 23, 2013
Merged

Fix issue with default scope clashing with deletion.#70
radar merged 1 commit into
rubysherpas:masterfrom
heisenbugged:master

Conversation

@laspluviosillas
Copy link
Copy Markdown

Fixes #37

In certain edge case scenarios default_scopes can interfere with the SQL Paranoia generates to issue a record hide. Both update_column and update_attribute use default scopes. Take the following edge case scenario:

class User < ActiveRecord::Base
  default_scope :include => :login, :order => "logins.first_name" 
  belongs_to :login
  acts_as_paranoid
end

In this case Paranoia throws the following SQL error when trying to hide/destroy a User record: ActiveRecord::StatementInvalid: PG::Error: ERROR: missing FROM-clause entry for table "logins"

My particular case is a very edge case scenario, but I can see the default scoping being a broader problem.

By adding unscoped to the deletion query default scope issues are avoided. In this case since Paranoia is simply saving an attribute on an already found and instantiated object, adding unscoped shouldn't impact the functionality of Paranoia at all. In fact, unscoped is only a class method.

…uses default scopes which can collide with deletion.
@laspluviosillas
Copy link
Copy Markdown
Author

Apparently this has been fixed in Rails branch ... I guess if it's fixed in newer versions of Rails this change is not that significant and only allows better backwards compatibility.

radar added a commit that referenced this pull request Sep 23, 2013
Fix issue with default scope clashing with deletion.
@radar radar merged commit 62756c0 into rubysherpas:master Sep 23, 2013
@radar
Copy link
Copy Markdown
Collaborator

radar commented Sep 23, 2013

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants