0
假设我有对面的包括Rails的
#post.rb
class Post < ActiveRecord::Base
default_scope includes(:user)
什么意思时,我不希望包括用户我做的时候我取一个帖子?
,例如,当我删除帖子
假设我有对面的包括Rails的
#post.rb
class Post < ActiveRecord::Base
default_scope includes(:user)
什么意思时,我不希望包括用户我做的时候我取一个帖子?
,例如,当我删除帖子
可以使用无范围的范围。方法参考:http://apidock.com/rails/ActiveRecord/Scoping/Default/ClassMethods/unscoped
例如,试图删除帖子对象时:
def destroy
@post = Post.unscoped.find(params[:id])
# destroy code here
end
这会在你的数据库中搜索,没有任何范围。