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

build_stubbed does not fill id for uuid column type with SQLServer #1618

Open
vividmuimui opened this issue Jan 19, 2024 · 0 comments
Open
Labels

Comments

@vividmuimui
Copy link

Description

When using SQLServer and 'uuid' as the primary key type, they 'build_stubbed' method does not automatically fill the id column. I would assume that this is filled independent of the column type.

def uuid_primary_key?(result_instance)
result_instance.respond_to?(:column_for_attribute) &&
(column = result_instance.column_for_attribute(result_instance.class.primary_key)) &&
column.respond_to?(:sql_type) &&
column.sql_type == "uuid"
end

I'm thinking the code here is the problem.

image

In SQLServer, the column.sql_type seems to be "uniqueidentifier".
I think it might work if I use column.type, but I don't know if this is a problem in other databases, so I've raised an issue.

Reproduction Steps

Sample code → https://github.com/vividmuimui/sqlserver-factorybot/commits/main/

Expected behavior

When you use build_stubbed, the primary key is always set. Also if you use the uuid type.

Actual behavior

The id of the generated instance is nil.

System configuration

factory_bot version: 6.4.5
rails version: 7.1.3
ruby version: v3.3.0

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

No branches or pull requests

1 participant