Created
December 13, 2016 22:55
-
-
Save kml/79595771e183b3001be5a691ac1f319e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
# https://github.com/mongodb/mongoid/blob/4789bfffd3cbfa065eb7be7f34fbac122278a0ae/lib/mongoid/criteria.rb#L324 | |
require "mongoid/criteria" | |
module Mongoid | |
class Criteria | |
OnlyWhenDefaultScopeError = Class.new(StandardError) | |
alias :mongoid_criteria_only :only | |
private :mongoid_criteria_only | |
def only(*args) | |
if scoped? && options[:fields].present? && args.flatten != options[:fields].keys | |
raise OnlyWhenDefaultScopeError, "Using #{klass}#only for criteria with default_scope already defining field for projection.\nUse #{klass}#unsoped method." | |
end | |
mongoid_criteria_only(*args) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment