Hi all,
I ''m trying to add a node to a tree (tabel has multiple trees).
@node.save
@node.move_to_child_of(1)
# 1 is the id of the parent node
When trying to add the node I get an error:
  SQL (0.000000)   BEGIN
BEGIN
  SQL (0.000000)   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 ''? ? "root_id IS NULL" :
"root_id #{root_id}")'' at line 1: SELECT max(rgt) AS max_rgt
FROM `nodes` WHERE
(root_id.nil? ? "root_id IS NULL" : "root_id = #{root_id}")
  SQL (0.000000)   ROLLBACK
Since I have multiple trees I defined a scope in my node model:
class Node < ActiveRecord::Base
  acts_as_nested_set :scope => :club_id
  has_one :club
  ...
class Club < ActiveRecord::Base
  belongs_to :node
  ...
When I remove this scope I don''t get the error.
additional info:
Node table
id-int(11)
club_id-int(11)
parent_id-int(11)
lft-int(11) 			
rgt-int(11) 			
name-varchar(100)
Someone knows what I''m doing wrong?
Regards,
Stijn
Quoting Gecke R?n <tarscher at gmail.com>:> SQL (0.000000) 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 ''? ? "root_id IS NULL" : "root_id > #{root_id}")'' at line 1: SELECT max(rgt) AS max_rgt FROM `nodes` WHERE > (root_id.nil? ? "root_id IS NULL" : "root_id = #{root_id}")...> Someone knows what I''m doing wrong?Somehow you are getting uninterpreted ruby code in your SQL. I don''t see anything in the code fragments you sent that is setting these conditions (and then not interpreting them). I would poke around in the call stack looking for files in your code - or in the betternestedset plugin to try to find the code fragment above. Then try to see why it is slapping straight ruby into the SQL query. -- Cynthia Kiser
I found a simular problem and using up to date code fixed the issue. Regards, Stijn On Wed, May 28, 2008 at 6:27 PM, Cynthia Kiser <cnk at caltech.edu> wrote:> Quoting Gecke R?n <tarscher at gmail.com>: >> SQL (0.000000) 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 ''? ? "root_id IS NULL" : "root_id >> #{root_id}")'' at line 1: SELECT max(rgt) AS max_rgt FROM `nodes` WHERE >> (root_id.nil? ? "root_id IS NULL" : "root_id = #{root_id}") > > ... > >> Someone knows what I''m doing wrong? > > Somehow you are getting uninterpreted ruby code in your SQL. I don''t > see anything in the code fragments you sent that is setting these > conditions (and then not interpreting them). I would poke around in > the call stack looking for files in your code - or in the > betternestedset plugin to try to find the code fragment above. Then > try to see why it is slapping straight ruby into the SQL query. > > -- > Cynthia Kiser > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk >