Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error: "alize does not work with default scope" #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/mongoid/alize/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'active_support/configurable'

module Mongoid
module Alize
include ActiveSupport::Configurable

config_accessor :unscoped do
false
end

class << self
def setup
yield config
end
end
end
end
3 changes: 2 additions & 1 deletion lib/mongoid/alize/to_callback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def find_relation
end

def iterable_relation
"[self.#{relation}].flatten.compact"
scope = Mongoid::Alize.config.unscoped ? 'unscoped' : 'scoped'
"[self.#{relation}.#{scope}].flatten.compact"
end

def set_callback
Expand Down
2 changes: 2 additions & 0 deletions lib/mongoid_alize.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'mongoid/alize/config'

require 'mongoid/alize/errors/alize_error'
require 'mongoid/alize/errors/invalid_field'
require 'mongoid/alize/errors/already_defined_field'
Expand Down