Rails在prod和dev服务器上的原始sql查询中给出不同类型的结果

时间:2015-10-12 08:04:33

标签: ruby-on-rails activerecord orm

当我使用ActiveRecord::Base.connection.execute运行直接原始sql时,dev和prod服务器正在生成不同类型的结果,尽管两者都是正确的。

QUERY(在rails控制台中):

query = ActiveRecord::Base.connection.execute("SELECT courses.name as course, round(count(placements.id)*100/count(students.id),2) as placed, count(placements.id) as total FROM courses LEFT JOIN students ON courses.id = students.course_id LEFT JOIN  placements ON placements.student_id = students.id where students.course_id<>1 group by course")

DEV SERVER

 #<Mysql2::Result:0xab44ca4 @query_options={:as=>:array, :async=>false, :cast_booleans=>false, :symbolize_keys=>false, :database_timezone=>:utc, :application_timezone=>nil, :cache_rows=>true, :connect_flags=>-2147442171, :cast=>true, :default_file=>nil, :default_group=>nil, :adapter=>"mysql2", :pool=>5, :timeout=>5000, :encoding=>"utf8", :database=>"ietplacementdb_dev", :username=>"ietplacementuser", :password=>"placement@pass15", :socket=>"/var/run/mysqld/mysqld.sock", :flags=>2}> 

query.as_json

[["M.C.A.", "2.0", 1], ["M.Tech.", "20.0", 2]] 

PROD SERVER:

[{"course"=>"M.C.A.", "placed"=>0.0, "total"=>0, 0=>"M.C.A.", 1=>0.0, 2=>0}, {"course"=>"M.Tech.", "placed"=>0.0, "total"=>0, 0=>"M.Tech.", 1=>0.0, 2=>0}] 

query.as_json

[{"course"=>"M.C.A.", "placed"=>0.0, "total"=>0, "0"=>"M.C.A.", "1"=>0.0, "2"=>0}, {"course"=>"M.Tech.", "placed"=>0.0, "total"=>0, "0"=>"M.Tech.", "1"=>0.0, "2"=>0}] 

0 个答案:

没有答案