jashmenn / activeuuid

Binary uuid keys in Rails
MIT License
340 stars 124 forks source link

SQL (MySQL) errors in complex arel queries #78

Closed stevegoobermanhill closed 8 years ago

stevegoobermanhill commented 8 years ago

Hi, I've been having issues with ActiveUUID producing incorrect SQL queries with fairly complex query sets. It looks like the query is being built with an unquoted string representation of the UUID. I suspect that the UUID should at least be quoted, if not a binary string.

The particular issue here involves a where clause with a list of uuids (ie where(id: uuid_array)) - so possibly the array of UUIDs in the where clause is being output as to_s rather than than the raw output

Sample problem (bad SQL is in where clause):

ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column '031cb9ba' in 'where clause': 
SELECT 
  COUNT(*) AS count_all, 
  state_id AS state_id, 
  entry_from AS entry_from
FROM `state_periods` 
INNER JOIN `states` ON `states`.`id` = `state_periods`.`state_id` 
INNER JOIN `state_machines` ON `state_machines`.`id` = `states`.`state_machine_id` 
WHERE (states.state_machine_id in (031cb9ba-b3dd-44b3-b1a1-09906540274b,eac88a3c-af18-4dfa-9707-25f2ac469d50)) 
GROUP BY `state_periods`.`state_id`, `state_periods`.`entry_from`
stevegoobermanhill commented 8 years ago

Resolved - application specific problem - sorry to bother you