Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queries using UUID foreign keys failing #61

Open
MarkPare opened this issue Jan 20, 2024 · 0 comments
Open

Queries using UUID foreign keys failing #61

MarkPare opened this issue Jan 20, 2024 · 0 comments

Comments

@MarkPare
Copy link

MarkPare commented Jan 20, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant