Topic: acts_as_tree throwing an error when I try and delete

I'm really starting to hate acts_as_tree.

I'm trying to destroy a category entry and I get a error about the parent_id

#error
Mysql::Error: #42S22Unknown column 'Category' in 'order clause': SELECT * FROM categories WHERE (categories.parent_id = 26)  ORDER BY Category
RAILS_ROOT: ./script/../config/..

Here's what I got, just guessing at this

#Category model
acts_as_tree :order => name, :dependent => :delete_all

#standard category controller
  def destroy
    Category.find(params[:id]).destroy
    redirect_to :action => 'list'
  end


*sigh*  Thanks

Re: acts_as_tree throwing an error when I try and delete

I think the SQL is called from some other code. Perhaps the "list" action. Can you post that?

I haven't had any problems with acts_as_tree.

Railscasts - Free Ruby on Rails Screencasts

Re: acts_as_tree throwing an error when I try and delete

just your standard list action

def list
    @category_pages, @categories = paginate :categories, :per_page => 10
  end

Re: acts_as_tree throwing an error when I try and delete

That's strange. Does your acts_as_tree definition in the Category class have an :order attribute? Are you defining :order => "Category" anywhere in the app?

If not, please post the stack trace for the error.

Railscasts - Free Ruby on Rails Screencasts

Re: acts_as_tree throwing an error when I try and delete

the model also has "has_many :products"

stack trace

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adapter.rb:120:in `log'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:184:in `execute'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:336:in `select'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:175:in `select_all'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:390:in `find_by_sql'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:924:in `find_every'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:381:in `find'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:83:in `find'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:111:in `find_target'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/association_proxy.rb:116:in `load_target'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/association_proxy.rb:109:in `method_missing'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:90:in `method_missing'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks.rb:346:in `callback'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks.rb:346:in `callback'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks.rb:341:in `each'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks.rb:341:in `callback'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks.rb:331:in `destroy_without_transactions'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/transactions.rb:122:in `destroy'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/database_statements.rb:51:in `transaction'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/transactions.rb:91:in `transaction'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/transactions.rb:118:in `transaction'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/transactions.rb:122:in `destroy'
#{RAILS_ROOT}/app/controllers/admin/category_controller.rb:62:in `destroy'
-e:4:in `load'
-e:4

Thanks ryan

Re: acts_as_tree throwing an error when I try and delete

In this line:

acts_as_tree :order => name, :dependent => :delete_all

Is 'name' a variable that's been set?  It looks like it's a string with the value 'Category'

Re: acts_as_tree throwing an error when I try and delete

SONUVA!!!!!!  forgot the quotes around "name".  sorry false alarm.  thanks for making me double check danger.