mysql-binuuid-rails icon indicating copy to clipboard operation
mysql-binuuid-rails copied to clipboard

Queries using UUID foreign keys failing

Open MarkPare opened this issue 1 year ago • 0 comments

I have 3 tables

class User < ActiveRecord::Base
  attribute :id, MySQLBinUUID::Type.new
  has_many :locations_users
  has_and_belongs_to_many :locations
end

class Location < ActiveRecord::Base
end

class LocationsUser < ActiveRecord::Base
  attribute :user_id, MySQLBinUUID::Type.new
  belongs_to :location
  belongs_to :user
end

If I then try to call user.locations I get a query that looks like this:

SELECT  1 AS one FROM `locations` INNER JOIN `locations_users` ON `locations`.`id` = `locations_users`.`location_id` WHERE `locations_users`.`user_id` = x'39633065333063302d326366362d343735632d393564392d366633376236333331383461' AND `locations`.`id` = 1 LIMIT 1

where the value of locations_uses.user_id is not correct.

If I run just LocationsUser.where(user_id: "9c0e30c0-2cf6-475c-95d9-6f37b633184a"), the query looks correct and returns a result as expected:

SELECT `locations_users`.* FROM `locations_users` WHERE `locations_users`.`user_id` = x'9c0e30c02cf6475c95d96f37b633184a'

It looks like in the locations_users query, the user_id value is getting mangled, possibly related to this issue.

Any suggestions?

Rails 5.2.8.1 Ruby 2.6.0 mysql-binuuid-rails 1.3.0

MarkPare avatar Jan 20 '24 08:01 MarkPare