Coder Social home page Coder Social logo

saks / mongoid_acts_as_tree Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ramdiv/mongo_mapper_acts_as_tree

32.0 2.0 17.0 80 KB

ActsAsTree for Mongoid

Home Page: http://github.com/ramdiv/mongo_mapper_acts_as_tree

License: MIT License

Ruby 100.00%

mongoid_acts_as_tree's Introduction

mongoid-acts_as_tree

This is an implementation of a tree structure for Mongoid.

Installation

Install as gem

gem install mongoid_acts_as_tree

Usage

Enable the tree functionality by declaring acts_as_tree on your model

class Category
  include Mongoid::Document
  include Mongoid::Acts::Tree

  field :name, :type => String

  acts_as_tree
end

The method accepts :parent_id_field, :path_field, :depth_field, :order as a hash.

:parent_id_field, :path_field, :depth_field => override the default field names
:order => control the order (format ['value', 'asc'] or [['field_1', 'asc'], ['field_2', 'desc']])

Check the test_tree.rb for examples.

About bugs

Use it. If you find any bugs, contact me (if possible with a test case) or patch it yourself (see next section).

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2009 Jakob Vidmar. See LICENSE for details.

mongoid_acts_as_tree's People

Contributors

davekrupinski avatar jakuboboza avatar papipo avatar ramdiv avatar saberma avatar saks avatar snyff avatar timoschilling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mongoid_acts_as_tree's Issues

Why not embedded?

Hello,

just out of interest: why use references and not embeds in a document database that can do trees very well?

--Jan

Add support to assign parent_id

Hi,

I would like to be able to assign a parent_id, since that's how usually things are handled in forms.
right now the gem does not handle changing path and depth fields when you assign the parent_id directly.

Thanks.

Rails 3.1 DEPRECATION WARNING: class_inheritable_attribute

Under Rails 3.1 class_inheritable_attribute is deprecated

DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from <class:Category> at /Users/xxxx/Sites/rails/xxxx/app/models/category.rb:14)

depth field

There may be something that i'm missing ( i just started using mongodb ), but why do you keep the node depth as a separate field? Isn't this the same thing as path_field.length?

moving nodes

moving nodes works fine if the moved node has no children (by setting the parent_id) , it doesn't work though for moving nodes with children.

from console
a = Node.find(:first, :conditions => {"name" => "test"})
a.parent_id = "xxxx"
a.save!

NoMethodError: undefined method _id' for "test":String from /Library/Ruby/Gems/1.8/bundler/gems/mongoid_acts_as_tree-7fce729/lib/mongoid_acts_as_tree.rb:84:infix_position'
from /Library/Ruby/Gems/1.8/bundler/gems/mongoid_acts_as_tree-7fce729/lib/mongoid_acts_as_tree.rb:175:in move_children' from /Library/Ruby/Gems/1.8/bundler/gems/mongoid_acts_as_tree-7fce729/lib/mongoid_acts_as_tree.rb:174:ineach'
from /Library/Ruby/Gems/1.8/bundler/gems/mongoid_acts_as_tree-7fce729/lib/mongoid_acts_as_tree.rb:174:in move_children' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/callbacks.rb:425:in_run_save_callbacks'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/callbacks.rb:93:in send' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/callbacks.rb:93:inrun_callbacks'
from /Library/Ruby/Gems/1.8/bundler/gems/mongoid-1a06b10/lib/mongoid/persistence/update.rb:43:in persist' from /Library/Ruby/Gems/1.8/bundler/gems/mongoid-1a06b10/lib/mongoid/persistence.rb:79:inupdate'
from /Library/Ruby/Gems/1.8/bundler/gems/mongoid-1a06b10/lib/mongoid/persistence.rb:125:in upsert' from /Library/Ruby/Gems/1.8/bundler/gems/mongoid-1a06b10/lib/mongoid/persistence.rb:70:insave!'
from (irb):14

bump version 0.1.7

Hey,
I had some problems that were fixed only with the code on master branch. Are you planning to bump version 0.1.7 any time soon?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.