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
这将在您的数据库中搜索,不包含任何范围