0

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

Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244

1 Answers1

1

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.

Kzu
  • 783
  • 4
  • 10