-
Notifications
You must be signed in to change notification settings - Fork 550
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
to-one association is generated when 'UNIQUE' set on a composite key(with multiple columns) #77
Comments
I'm actually a bit confused about what's going on here because I don't know what the indexes/constraints/keys are on your user_role table. Is it possible to do a: show create table user;
show create table user_role;
show create table role; This would help me a lot. |
I had to edit my above comment, it was incomplete. Also: If you don't want to share your table structure, omit any of the columns that aren't necessary (everything except primary and foreign keys). |
Hi, @aarondl Thanks for asking, and sorry for the late reponse, I just made an example with 3 tables: In
Attached is the generated orm: |
So, finally got a chance to look into this in depth. It appears that the constraint finding mechanism is indeed wrong. I think the proper fix is change make it such that a unique constraint only changes a relationship into a one-to-one if the foreign key is the only key in the constraint. Which essentially means that the column count in the constraint affecting the key is 1. What do you think about this logic? |
Determine unique associations for unique constraints with only 1 keys
@aarondl Yeah, it works! Thank you! And I made a PR, trying to fix it Schema for testing:
|
- Fix formatting on giant postgres query - Invert the section that looks for unique constraints to look for a constraint and join to the constraint_column_usage to be more in line with the mysql query and also it makes a little bit more sense. - Add more checks to ensure the schema is being enforced in the postgres side of things as several pieces in the unique checks were missing it which would lead to false positives. - Fix #77 for postgres
@yangyuqian Is it possible you could test out the dev branch of sqlboiler right now to see if your issue is fixed there? |
Oops, didn't mean "right now". Also if it looks good, we'll do a release of sqlboiler :) |
Sure, I'm looking into it |
@aarondl I've tested against my schema, it's working on dev branch, thank you |
Hi,
It seems a bug to create to-one association when a composite key is unique,
i.e.
When the composite key in user_role(user_id, role_id) is UNIQUE, a to-one association will be generated on both User and UserRole
And I can fix this by omit the UNIQUE composite keys and still generate to-many associations for them(line number 134):
Do you think this is a feasible fix? I'd like to submit a PR for it
The text was updated successfully, but these errors were encountered: