【发布时间】:2012-12-17 10:23:32
【问题描述】:
假设我有
#post.rb
class Post < ActiveRecord::Base
default_scope includes(:user)
如果我不想在获取帖子时包含用户,该怎么办?
例如,当我删除帖子时
【问题讨论】:
标签: ruby-on-rails-3 eager-loading
假设我有
#post.rb
class Post < ActiveRecord::Base
default_scope includes(:user)
如果我不想在获取帖子时包含用户,该怎么办?
例如,当我删除帖子时
【问题讨论】:
标签: ruby-on-rails-3 eager-loading
您可以使用无范围的范围。方法参考:http://apidock.com/rails/ActiveRecord/Scoping/Default/ClassMethods/unscoped
例如,当试图删除 Post 对象时:
def destroy
@post = Post.unscoped.find(params[:id])
# destroy code here
end
这将在您的数据库中搜索,没有任何范围。
【讨论】: