diff --git a/README.md b/README.md index 439faf4..6b70759 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A tree structure for Mongoid documents using the materialized path pattern ## Requirements -* mongoid (>= 4.0, < 6.0) +* mongoid (>= 4.0, < 7.0) For a mongoid 3.x compatible version, please use mongoid-tree 1.0.x, for a mongoid 2.x compatible version, please use mongoid-tree 0.7.x. diff --git a/lib/mongoid/tree.rb b/lib/mongoid/tree.rb index 3d8fb49..b559d3c 100644 --- a/lib/mongoid/tree.rb +++ b/lib/mongoid/tree.rb @@ -87,7 +87,17 @@ module Tree included do has_many :children, :class_name => self.name, :foreign_key => :parent_id, :inverse_of => :parent, :validate => false - belongs_to :parent, :class_name => self.name, :inverse_of => :children, :index => true, :validate => false + options = { + :class_name => self.name, + :inverse_of => :children, + :index => true, + :validate => false, + :optional => true + } + + options.delete(:optional) if Gem::Version.new(Mongoid::VERSION) < Gem::Version.new('6.0.0.beta') + + belongs_to :parent, options field :parent_ids, :type => Array, :default => [] index :parent_ids => 1 diff --git a/mongoid-tree.gemspec b/mongoid-tree.gemspec index 6e46b3f..feb1af8 100644 --- a/mongoid-tree.gemspec +++ b/mongoid-tree.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |s| s.files = Dir.glob('{lib,spec}/**/*') + %w(LICENSE README.md Rakefile Gemfile .rspec) - s.add_runtime_dependency('mongoid', ['< 6.0', '>= 4.0']) + s.add_runtime_dependency('mongoid', ['< 7.0', '>= 4.0']) s.add_development_dependency('rake', ['>= 0.9.2']) s.add_development_dependency('rspec', ['~> 3.0']) s.add_development_dependency('yard', ['~> 0.8'])