# Multiple Trees in a better\_nested\_set Table

**URL:** <https://www.ruby-forum.com/t/multiple-trees-in-a-better-nested-set-table/126046>\
**Category:** Ruby\
**Created:** [January 15, 2008, 12:34am UTC](https://www.ruby-forum.com/t/multiple-trees-in-a-better-nested-set-table/126046 "2008-01-15T00:34:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdsykes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f14d63/32.png) [@sdsykes](https://www.ruby-forum.com/u/sdsykes)\
**Post date:** [January 15, 2008, 12:34am UTC](https://www.ruby-forum.com/t/multiple-trees-in-a-better-nested-set-table/126046/1 "2008-01-15T00:34:11Z")

</div>

Hi All,

I also sent this message out to the better\_nested\_set mailing list so  
I’ll  
update this thread  
if that yields a response.

I’m having trouble configuring a table to be able to accommodate  
multiple  
trees.  
I have a feeling that this is a common question but a few creative  
searches  
came up empty.  
I tried using [http://wiki.rubyonrails.org/rails/pages/BetterNestedSet](http://wiki.rubyonrails.org/rails/pages/BetterNestedSet) as  
a  
guide and created  
a tree\_id column in my table and declared acts\_as\_nested\_set, :scope =\>  
:tree\_id in my model.

My rspec tests began failing and reporting the MYSQL error below:

\*Mysql::Error: #42000You have an error in your SQL syntax; check the  
manual that corresponds to your MySQL server version for the right  
syntax to use near ‘? ? “tree\_id IS NULL” : “tree\_id = #{tree\_id}” AND  
(parent\_id IS NULL)) ORDER B’ at line 1: SELECT \* FROM studies WHERE  
(tree\_id.nil? ? “tree\_id IS NULL” : “tree\_id = #{tree\_id}” AND  
(parent\_id IS NULL)) ORDER BY lft  
\*  
Any insight is greatly appreciated. I guess I’m a bit hazy on what  
:scope  
is used for and how to use it.  
I’ve also played around with making multiple trees without :scope in my  
directive and it most of my method calls  
ended up looking like I’d expect. (.root? and .root got weird on me)

-Thanks!  
Stephen
