我使用friendly_id 4.0.0鋼軌3.0.1和0.2.3 tiny_tds(因爲我有一個SQL Server數據庫作爲Rails應用程序後端)friendly_id不適用於sql server和tiny_tds?
在我的模型我有
extend FriendlyId
friendly_id :friendly_name, :use => [:slugged]
當我嘗試創建從鐵軌控制檯類的新紀錄,我得到以下錯誤:
ActiveRecord::StatementInvalid: TinyTds::Error: 'LENGTH' is not a recognized built-in function name.: SELECT TOP (1) [j_service_provider].* FROM [j_service_provider] WHERE ([slug] = N'' OR [slug] LIKE N'--%') ORDER BY LENGTH([slug]) DESC, [slug] DESC
這是因爲SQL Server不具備長度的功能,但有一個LEN功能。
所以,如果我在衝突的方法改變線48上查詢在slug_generator.rb到:
scope = scope.order("LEN(#{column}) DESC, #{column} DESC")
的創建工作。
但是,如果我運行find_each(&:save)
,它仍然不起作用,但爲數據庫中的現有記錄生成段落。
是否還需要一些其他配置更改使friendly_id與使用tiny_tds的sql server一起工作?
這是堆棧跟蹤:
ActiveRecord::StatementInvalid: TinyTds::Error: 'LENGTH' is not a recognized built-in function name.: SELECT TOP (1) [company].* FROM [company] WHERE ([slug] = N'' OR [slug] LIKE N'--%') ORDER BY LENGTH([slug]) DESC, [slug] DESC
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:202:in `log'
from /usr/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-3.0.7/lib/active_record/connection_adapters/sqlserver/database_statements.rb:249:in `raw_select'
from /usr/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-3.0.7/lib/active_record/connection_adapters/sqlserver/database_statements.rb:193:in `select'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/query_cache.rb:56:in `select_all'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/base.rb:467:in `find_by_sql'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/relation.rb:64:in `to_a'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/relation/finder_methods.rb:333:in `find_first'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/relation/finder_methods.rb:122:in `first'
from /usr/lib/ruby/gems/1.8/gems/friendly_id-4.0.0/lib/friendly_id/slug_generator.rb:38:in `conflict'
from /usr/lib/ruby/gems/1.8/gems/friendly_id-4.0.0/lib/friendly_id/slug_generator.rb:33:in `conflict?'
from /usr/lib/ruby/gems/1.8/gems/friendly_id-4.0.0/lib/friendly_id/slug_generator.rb:23:in `generate'
from /usr/lib/ruby/gems/1.8/gems/friendly_id-4.0.0/lib/friendly_id/slugged.rb:257:in `set_slug'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/callbacks.rb:424:in `_run_validation_callbacks'
from /usr/lib/ruby/gems/1.8/gems/activemodel-3.0.1/lib/active_model/validations/callbacks.rb:67:in `run_validations!'
from /usr/lib/ruby/gems/1.8/gems/activemodel-3.0.1/lib/active_model/validations.rb:179:in `valid?'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/validations.rb:55:in `valid?'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/validations.rb:75:in `perform_validations'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/validations.rb:43:in `save'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/attribute_methods/dirty.rb:21:in `save'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/transactions.rb:237:in `save'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/transactions.rb:289:in `with_transaction_returning_status'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/transactions.rb:204:in `transaction'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/transactions.rb:287:in `with_transaction_returning_status'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/transactions.rb:237:in `save'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/transactions.rb:248:in `rollback_active_record_state!'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/transactions.rb:236:in `save'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.1/lib/active_record/base.rb:498:in `create'