cancancan
cancancan copied to clipboard
Cannot use MySQL UUID through binary type
Steps to reproduce
I have used this gem: mysql-binuuid-rails
I have a CanCan rule like this:
can ADMIN_ABILITIES, Profile, account: {account_users: {role: "administrator", user_id: current_user.id}} if signed_in?
accessible_by
uses some weird ID's (notice they are very long):
Profile.accessible_by(admin_ability).to_sql
SELECT
DISTINCT `profiles`.*
FROM
`profiles`
LEFT OUTER JOIN `accounts` ON
`accounts`.`id` = `profiles`.`account_id`
LEFT OUTER JOIN `account_users` ON
`account_users`.`account_id` = `accounts`.`id`
WHERE
((`account_users`.`user_id` = x'30336364373439632d326536322d343737372d386563662d626134326539376136323536') OR
(`account_users`.`role` = 'administrator' AND `account_users`.`user_id` = x'30336364373439632d326536322d343737372d386563662d626134326539376136323536'))
Normal ActiveRecord works fine (notice they are shorter):
Profile.joins(account: :account_users).where(account_users: {user_id: admin.id}).to_sql
SELECT
`profiles`.*
FROM
`profiles`
INNER JOIN `accounts` ON
`accounts`.`id` = `profiles`.`account_id`
INNER JOIN `account_users` ON
`account_users`.`account_id` = `accounts`.`id`
WHERE
`account_users`.`user_id` = x'03cd749c2e6247778ecfba42e97a6256'
``
### Expected behavior
I would have expected it to use the ID's as when using normal ActiveRecord query building.
### Actual behavior
It uses wrong ID's that are very long.
### System configuration
**Rails version**: 6.1.1
**Ruby version**: 2.7.2
**CanCanCan version** Same things happens on 3.2.1 & Git master
### Gist
I tried creating a Gist reproducing the issue, but it works when I run it...
https://gist.github.com/kaspernj/708c62f8c9d435353dc9b6f146f1851a