Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 轨道中包含的对面_Ruby On Rails 3_Eager Loading - Fatal编程技术网

Ruby on rails 3 轨道中包含的对面

Ruby on rails 3 轨道中包含的对面,ruby-on-rails-3,eager-loading,Ruby On Rails 3,Eager Loading,假设我有 #post.rb class Post < ActiveRecord::Base default_scope includes(:user) #post.rb 类Post

假设我有

#post.rb

class Post < ActiveRecord::Base

default_scope includes(:user)
#post.rb
类Post
当我获取帖子时不想包含用户时,我该怎么办


例如,当我删除一篇文章时,您可以使用unscoped范围。方法参考:

例如,尝试删除Post对象时:

def destroy
  @post = Post.unscoped.find(params[:id])
  # destroy code here
end
这将在您的数据库中搜索,不包含任何范围