# Acts\_as\_tree, acts\_as\_list and is invincible (help!)

**URL:** <https://www.ruby-forum.com/t/acts-as-tree-acts-as-list-and-is-invincible-help/61963>\
**Category:** Rails\
**Created:** [May 30, 2006, 10:03am UTC](https://www.ruby-forum.com/t/acts-as-tree-acts-as-list-and-is-invincible-help/61963 "2006-05-30T10:03:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![samo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@samo](https://www.ruby-forum.com/u/samo)\
**Post date:** [May 30, 2006, 10:03am UTC](https://www.ruby-forum.com/t/acts-as-tree-acts-as-list-and-is-invincible-help/61963/1 "2006-05-30T10:03:04Z")

</div>

So I have the following model

class Topic \< ActiveRecord::Base  
belongs\_to :topic  
has\_many :topics, :order =\> :position  
acts\_as\_tree :order =\> :position  
acts\_as\_list :scope =\> :topic\_id  
end

that I use for a site’s navigation. Everything (list, create, edit, even  
the drag&drop sort) works fine, except the destroy function, which the  
vanilla version

def destroy  
Topic.find(params[:id]).destroy  
redirect\_to :action =\> ‘list’  
end

which gives me the following error

“Mysql::Error: Unknown column ‘topics.parent\_id’ in ‘where clause’:  
SELECT \* FROM topics WHERE (topics.parent\_id = 39) ORDER BY position”

Now, my table has the normal “id” field and a “topic\_id” field that I am  
using instead of “parent\_id”, so I have have both - a list and a tree.  
And, like I said, it works great and I was surprised at how simple the  
whole thing was - until I tried to delete a topic and the whole thing  
exploded.

I also already tried

belongs\_to :topic, :foreign\_key =\> ‘topic\_id’, :class\_name =\> ‘Topic’

but that producced the same error.

So. Uhm. Help? :o)

Thanks for your time guys!

Samo

---

<div class="post-metadata">

**Author:** ![samo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@samo](https://www.ruby-forum.com/u/samo)\
**Post date:** [May 30, 2006, 10:59am UTC](https://www.ruby-forum.com/t/acts-as-tree-acts-as-list-and-is-invincible-help/61963/2 "2006-05-30T10:59:57Z")

</div>

Hi,

Shouldn’t you specifiy the options foreign\_key in your acts\_as\_tree call  
? As you do not use the default column name parent\_id, I would try  
something like that :

acts\_as\_tree :order =\> :position, :foreign\_key =\> ‘topic\_id’

Bye,  
Thomas.

---

<div class="post-metadata">

**Author:** ![samo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@samo](https://www.ruby-forum.com/u/samo)\
**Post date:** [May 30, 2006, 11:23am UTC](https://www.ruby-forum.com/t/acts-as-tree-acts-as-list-and-is-invincible-help/61963/3 "2006-05-30T11:23:52Z")

</div>

I’m a newbie when it comes to Rails, so I didn’t know that (actually I  
tried the foreign\_key at all the wrong places…). Anyhow, thanks a lot

- that solved it!

Samo

Thomas wrote:

> Hi,
> 
> Shouldn’t you specifiy the options foreign\_key in your acts\_as\_tree call  
> ? As you do not use the default column name parent\_id, I would try  
> something like that :
> 
> acts\_as\_tree :order =\> :position, :foreign\_key =\> ‘topic\_id’
> 
> Bye,  
> Thomas.
