开发者

Rails 3 and ar_extensions: undefined method attribute_condition

开发者 https://www.devze.com 2023-02-16 21:23 出处:网络
I kept getting this error in my Rails app after upgrading to Rails 3. >> u.sent_messages NoMethodError: undefined method `attribute_condition\' for #Class:0x105523f18

I kept getting this error in my Rails app after upgrading to Rails 3.

>> u.sent_messages
NoMethodError: undefined method `attribute_condition' for #Class:0x105523f18
    from 开发者_C百科/Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/base.rb:1008:in `method_missing'
    from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:79:in `sanitize_sql_from_hash'
    from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:55:in `each_pair'
    from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:55:in `sanitize_sql_from_hash'
    from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:27:in `sanitize_sql'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/reflection.rb:131:in `send'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/reflection.rb:131:in `sanitized_conditions'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/association_proxy.rb:105:in `conditions'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/has_many_association.rb:103:in `construct_sql'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/association_collection.rb:24:in `initialize'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/has_many_association.rb:11:in `initialize'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations.rb:1492:in `new'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations.rb:1492:in `sent_messages'
    from (irb):36
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:488

Turns out I was still using the ar_extensions Gem from http://www.continuousthinking.com/tags/arext. For one thing they have a successor, for another there is a bulk insert option in ActiveRecord now which might be worth checking out (using Model.create([hash1, hash2, hash3, ...])).


ar-extensions is only for use in Rails 2.x. For Rails 3.x you should use the activerecord-import gem. It has the same import API.

https://github.com/zdennis/activerecord-import

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号