Closed silmaril-zz closed 14 years ago
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.save
This 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: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 FROM
hosttrees` 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 FROM locations
WHERE (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")?
The problem was with a syntax error in the model file.
Regards
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 FROM
hosttrees` WHERE (parent_id = ) (ActiveRecord::StatementInvalid)Do you need do to something special to set a node to root?