Thursday, May 04, 2006

Rails acts_as_threaded Plugin

Left a comment on the acts_as_threaded plugin page as a warning to someone using it that wants to use proper ids for their tables.

If you end up using a guid for the table primary key and root_id, it you need to enclose the "#{self[root_column]}" with quotes. If you don't the sql will get broken by the hyphens in the id.

Otherwise, it works well even when you combine it with guid self generating 36 char ids.

Lines with root_column will change from something like this:

self.class.update_all( "#{left_col_name} = (#{left_col_name} + 2)", "#{scope_condition} AND #{root_column} = #{self[root_column]} AND #{left_col_name} >= #{right_bound}" )

to become something like this:

self.class.update_all( "#{left_col_name} = (#{left_col_name} + 2)", "#{scope_condition} AND #{root_column} = '#{self[root_column]}' AND #{left_col_name} >= #{right_bound}" )

No comments: