Reputation: 32130
Assuming I have
#post.rb
class Post < ActiveRecord::Base
default_scope includes(:user)
what do I do when I don't want to include the user when I fetch a post?
for instance, when I delete a post
Upvotes: 0
Views: 553
Reputation: 783
You can use the unscoped scope. Method reference: http://apidock.com/rails/ActiveRecord/Scoping/Default/ClassMethods/unscoped
For example, when trying to delete the Post object :
def destroy
@post = Post.unscoped.find(params[:id])
# destroy code here
end
This will search in your database without any scope.
Upvotes: 1