Rodrigo Lueneberg
2014-Apr-11 01:34 UTC
Rails 4.1 activerecord_relation conversion to array problem
After I upgraded from rails 3.2 to 4.1 I am getting this error below. I researched that Rails 4.1 requires a conversion of an activerecord_relation to an array using to_a. I did use to_a but looks like rails is doing a select count behind the scenes. Do you know how to fix this? def index order_type = params[:order_type] @oh = OrderHeader.select("orders_header.*, users.username, users.id as customer_id, users.email, users.phone_work, users.phone_home, users.phone_cell"). joins("INNER JOIN users ON users.id = orders_header.customer_id "). where("orders_header.order_type='#{order_type}' and orders_header.customer_id=#{session[:user_id]}"). order("id desc"). paginate(:per_page => 10, :page => params[:page]) return @oh.to_a end Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*, users.username, users.id as customer_id, users.email, users.phone_work, users' at line 1: SELECT COUNT(orders_header.*, users.username, users.id as customer_id, users.email, users.phone_work, users.phone_home, users.phone_cell) FROM `orders_header` INNER JOIN users ON users.id = orders_header.customer_id WHERE (orders_header.order_type='order' and orders_header.customer_id=1) thanks Rod -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/210b8e0bee5a94fb272f83e706e5b568%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.