12spokes / acts_as_restful_list

Just like acts_as_list, but restful.
MIT License
14 stars 9 forks source link

destroy_all throws an error if there is an nil position in the list. #1

Open treybean opened 14 years ago

treybean commented 14 years ago

class Recommendation < ActiveRecord::Base acts_as_restful_list :scope => :list end

on postgres:

Recommendation.destroy_all returns

ActiveRecord::StatementInvalid: PGError: ERROR: syntax error at or near ")" LINE 1: ...sition = (position - 1) WHERE (list_id = 1 AND position > ) ^ : UPDATE "recommendations" SET position = (position - 1) WHERE (list_id = 1 AND position > ) from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:219:in log' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/postgresql_adapter.rb:550:inexecute' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:265:in update_sql' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/postgresql_adapter.rb:561:inupdate_sql' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:49:in update_without_query_dirty' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/query_cache.rb:18:inupdate' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:847:in update_all' from /Library/Ruby/Gems/1.8/gems/acts_as_restful_list-0.1.0/lib/acts_as_restful_list.rb:55:inreset_order_after_destroy' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:178:in send' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:178:inevaluate_method' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:166:in call' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:93:inrun' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:92:in each' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:92:insend' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:92:in run' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:276:inrun_callbacks' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/callbacks.rb:344:in callback' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/callbacks.rb:338:indestroy_without_transactions' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:229:in send' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:229:inwith_transaction_returning_status' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in transaction' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:182:intransaction' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:228:in with_transaction_returning_status' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:192:indestroy' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:877:in destroy_all' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:877:ineach' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:877:in `destroy_all'

treybean commented 14 years ago

Discovered this is only if one of the item's position is nil