chris / better_nested_set
- Source
- Commits
- Network (11)
- Issues (3)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
Pledgie Donations
Once activated, we'll place the following badge in your repository's detail box:
better_nested_set Rails plugin (my fork from official SVN)
-
why isn't there a move_to_root?
or how should I proceed to making a child a root because I can't change the parent_id to nil and reloadthx
MiddayComments
-
I'm trying to create a new root item in a tree. I get the following error:
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:219:in
log': Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1: SELECT max(hosttrees.rgt) AS max_rgt FROMhosttrees` WHERE (parent_id = ) (ActiveRecord::StatementInvalid)Do you need do to something special to set a node to root?
Comments
Can you provide a code sample, or better, a failing test case? Also, looks like you're using Rails 2.3.4. I'm still on 2.3.3, so it could be an issue that's come up with 2.3.4. I expect to jump to Rails 2.3.5 in the next few weeks, but until then won't know if that's the issue.
The real question is how do I create a root node?
Currently I'm using:
a = Class.new()
a.name = "text"
a.saveThis generates the error above...
Ok, now I'm using 2.3.3 and I'm getting the same error:
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract_adapter.rb:212:inlog': Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1: SELECT max(hosttrees.rgt) AS max_rgt FROMhosttrees` WHERE (parent_id = ) (ActiveRecord::StatementInvalid)Can you please let me know how I should create a root node for a tree?
Regards
The way you're doing it, or say Class.create(:name => 'text'), should work fine. I just did it and it works fine for me. When I do that, I see the following SELECT:
SELECT max(
locations.rgt) AS max_rgt FROMlocationsWHERE (1 = 1)So, not sure what's going on with the "parent_id=" bit. Do you have any non-standard configuration or naming? I assume you have parent_id, lft, and rgt columns in your table? It's also a bit unusual looking to see "hosttrees", instead of "host_trees", but maybe your class is named "Hosttree" (instead of "HostTree")?
-
Hi, i'm using this plugin to manage a structure of categories (one single root with, at now, 12-15000 children). I've noticed that running a simple script which create categories one after one at the end i had all the structure corrupted (lft and rgt not correct). I run a renumber_full_tree and everything went right again.
Then i removed some (~2-3000) categories with another simple script using the destroy method and after some (100-200) i had again all the structure broken. Then i used the delete method and called at the end the renumber_full_tree again, and it went right.
I'm very worried about this because the categories will increase exponentially (like one root and 500'000, 1'000'000 or even more children), and having this trouble would make all the website broken.
Do you know what would it be the cause?Comments
I'm not sure. When you say the structure is corrupt, is it corrupt right after the deletes, as in, have you reloaded the objects you are examining for correctness? I haven't had any problems. I'm using a smaller number of items in our case, but I don't see how the number would matter at all (the code either works or it doesn't). Are any exceptions being thrown?
Hi chris, yes, i reloaded the objects after the deletes.
For example before the script, i had a structure like this:root a a1 a11 a12 a2 a3 b b1 b2 b3 etc..Then after the creation/destroy i had something like:
root a a1 a11 a12 a2 a3 b b1 b2 b3 etc..Having another group of categories under another child (luckily only for lft and rgt, parent_id wasn't touched so i was able to just run a renumber_full_tree)
The only problem i think about is that i got all the categories and then checked them, like
Category.all.each do |category|
category.destroy if category.something = '...' and category.all_children_count.zero? endWithout reloading all the categories, but i think that this isn't the problems as in the before_destroy of the plugin there is a:
self.reload # in case a concurrent move has altered the indexeswhich should be the solution for this cases
There weren't any exceptions or other outputs (just that for the destroy it took a while, as there are a lot of records to update, i think)
Usually it works correctly when you create/destroy a single object, but having a lot of them it collapsed, i don't know if maybe because the db (mysql), the plugin or what else :)
Just an OT question, do you think that there would be problems having a lot (1-2 millions) of children under a single root?
I mean, about updates and stuff like that... if you add/destroy a child at the start and it has to update thousands/millions of rows with the new lft/rgt i think it would take quite a lot (and we know that users hate to wait too long :( ) -
in rails 2.3.4, attributes_with_quotes accepts 3 optional arguments, and in bns, it only accepts 2. this cause save to crash with a wrong number of arguments error.
Comments
Thanks for the report. I haven't moved to Rails 2.3.4 yet, so haven't come across this. Not sure when I will - probably in the next couple weeks, but that's about as best a guess as I have right now. I suggest submitting a patch (or if you fork and fix, do a pull request).
-
undefined method `siblings' for #<Class:0x50d6808>
2 comments Created 13 days ago by silmarilWhen I use the "roots" method it works. Records are created successfully and the tree works fine.
When trying to make use of "siblings" or any of the other methods, I get "undefined method" errors.
I'm using rails 2.3.3.
Comments





You just call move_to_child_of(nil).