Ruby on Rails Saturday, May 31, 2014

Until Rails 4.0.4 everything was working fine until I upgraded to latest
Rails version. It seems to be a bug because from the error message looks
like rails is doing just a count(Bla bla )without using properly using a
select count(id) from (SELECT COUNT(orders_header.id,
orders_header.created_at) FROM `orders_header` WHERE (shop_id=99 and
customer_id=1 and hash_key like
'539de64e8793790430052bc861dd0ff521334e32')

Is there a workaround for this problem?

query= OrderHeader.select("orders_header.id,
orders_header.created_at").where("shop_id=#{shop_id} and
customer_id=#{customer_id} and hash_key like
'#{current_hash_key}'").order("id desc")
if query.nil?
return true # no duplicates found
end
if (query.count>0) # duplicates found
# I get the error righ here
end
ERROR
SELECT COUNT(orders_header.id, orders_header.created_at) FROM
`orders_header` WHERE (shop_id=99 and customer_id=1 and hash_key like
'539de64e8793790430052bc861dd0ff521334e32')
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 ' orders_header.created_at) FROM `orders_header` WHERE
(shop_id=99 and customer_' at line 1: SELECT COUNT(orders_header.id,
orders_header.created_at) FROM `orders_header` WHERE (shop_id=99 and
customer_id=1 and hash_key like
'539de64e8793790430052bc861dd0ff521334e32')

--
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@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/bcb14d344979a0207b1f4923fbb06147%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment