Forum: Ruby on Rails acts_as_tree, acts_as_list and is invincible (help!)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6467119cb561dddb63b43547449a7a52?d=identicon&s=25 samo (Guest)
on 2006-05-30 10:03
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
B4988fe1d25f1afd8a9697ee3896db2d?d=identicon&s=25 Thomas (Guest)
on 2006-05-30 10:59
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.
6467119cb561dddb63b43547449a7a52?d=identicon&s=25 samo (Guest)
on 2006-05-30 11:23
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.
This topic is locked and can not be replied to.