The document discusses issues with default_scope in ActiveRecord when joining tables. Default scopes add conditions automatically that can't easily be removed. The presenter demonstrates different ways to try removing the default scope condition, such as unscoped, except, and unscope, but these don't work when includes or joins are used. The solution is to set the default_scopes array to empty for a subclass to remove the default scope. Default scopes can be convenient for single models but cause problems for more complex queries involving joins. Careful consideration of scopes is advised to avoid these issues.
16. includes¤·¤Æ¤ß¤ë¤¾
class Author < ActiveRecord::Base
has_many :posts
default_scope -> { where(status: :ok) }
end
class Post < ActiveRecord::Base
belongs_to :author
end
https://www.?ickr.com/photos/lintmachine/3652702115