Ruby on Rails Sunday, June 1, 2014

Rails introduced a breaking change to select and count being used together in the same relation. Either remove your call to "select", since it is unnecessary here, or call "count(:all)".

More info here: https://github.com/rails/rails/issues/15138

On Saturday, May 31, 2014 8:00:36 PM UTC-4, Ruby-Forum.com User wrote:
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/5d7bac77-906d-4467-ba42-254cf484401e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment