default_scope is applying too broadly #1306

Closed
dhh opened this Issue May 25, 2011 · 1 comment

Comments

Projects
None yet
2 participants
Owner

dhh commented May 25, 2011

class Todolist < ActiveRecord::Base
  default_scope where(trashed: false)

  has_many   :todos
  has_many   :comments, through: :todos
end

class Todo < ActiveRecord::Base
  default_scope where(trashed: false)

  belongs_to :todolist
  has_many   :comments, as: :commentable
end

class Comment < ActiveRecord::Base
  belongs_to :commentable, polymorphic: true
end

todolist.comments.update_all trashed: true
# => ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'todos.trashed' in 'where clause': UPDATE `comments` SET `trashed` = 1 WHERE `comments`.`trashed` = 0 AND `todos`.`trashed` = 0 AND `todos`.`todolist_id` = 968316918 ORDER BY created_at

@ghost ghost assigned jonleighton May 25, 2011

Member

jonleighton commented May 25, 2011

@dhh This looks like a dupe of #522, which occurs because Relation#update_all does not respect joins (and never has).

jake3030 pushed a commit to jake3030/rails that referenced this issue Jun 28, 2011

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