我将旧的应用程序从rails 2.3.2移动到2.3.18,将ruby 1.8.7-p72移动到1.8.7-p374。 (之后是ruby 1.9.3和rails 3)
我尝试的第一个问题应该是简单的问题。在控制台中:
?> User.find(:all, :joins => { :sms_users => :join_smsuser_campaigns },
:conditions => { :sms_users => {
:join_smsuser_campaigns => {
:campaign_id => 18 } } })
看起来很简单?
它给了我:
ActiveRecord::StatementInvalid: ActiveRecord::StatementInvalid
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:2363:in `sanitize_sql_hash_for_conditions'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:2079:in `map'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:2345:in `each'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:2345:in `map'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:2345:in `sanitize_sql_hash_for_conditions'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:2361:in `sanitize_sql_hash_for_conditions'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:2079:in `map'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:2345:in `each'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:2345:in `map'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:2345:in `sanitize_sql_hash_for_conditions'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:2274:in `sanitize_sql'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:1528:in `merge_conditions'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:1526:in `each'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:1526:in `merge_conditions'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:1838:in `add_conditions!'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:1721:in `construct_finder_sql'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:1582:in `find_every'
from /Users/decker/.rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.18/lib/active_record/base.rb:619:in `find'
from (irb):6>>
只是为了确认我实际上可以创建用户类型:
?> User.find(1)
=> #<User id: 1, date_created: "2008-01-06 17:22:12", email: "email@example.com", name: "First Last", phone_number: "1234567890", last_communication: "2012-11-09 22:34:43">
所以,看起来我可以创建User对象。
知道为什么这个简单的查询失败了吗?我已经阅读了2.3.18的activerecord文档,看起来我的例子就像他们展示的一些例子......也许我有一个宝石导致问题?从堆栈跟踪中看不出来。
答案 0 :(得分:0)
更改查询语法对我有用:
users = User.find(:all, :joins => { :sms_users => :join_smsuser_campaigns },
:conditions => { 'join_smsuser_campaigns.campaign_id' => session[:campaign_id].to_i},
:order => 'join_smsuser_campaigns.conversation_status DESC, join_smsuser_campaigns.last_communication DESC, sms_users.id ASC')