-
Notifications
You must be signed in to change notification settings - Fork 301
Foreign key improvements #1145
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
Foreign key improvements #1145
Conversation
For a composite reference, the foreign fields have to be checked against the parent fields for type equality. The parent field are found by searching the parent Entity, using 'getFD'. For the foreign fields,though, this is unecessary. Currently, for each composite field, we extract its fields name and search again for the same field using 'getFd'. This creates an unecessary round trip.
This required a small tweak to TH. This is because when the primary key is autogenerated it has an extra layer. So when TH defines a function :: ChildFields -> ParentKey, we need an extra unwrapping.
The `References` keyword can be omitted to have backwords compatibility. The fields before and after the key word must have the same length (and are type checked as before).
TH needed a small tweak, because the function ChildFields -> ParentKey can't be generated when we reference manual fields. This is just a utility function and missing it in this case shouldn't create any issues.
Tests for this are missing because there is not yet postgres support.
Nullable references are currently broken, since TH generates code which doesn't compile. The tests in this commit provide a good workaround to make this case work properly.
| , cDefaultConstraintName = Nothing | ||
| , cMaxLen = Nothing | ||
| , cReference = ref | ||
| -- TODO: Fix cascade reference is ignored |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this is available here
| a | ||
| [name] | ||
| (Util.dbIdColumnsEsc escape refdef) | ||
| -- TODO: Fix cascade reference is ignored |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like we can just copy it on down
| Right _ -> | ||
| SqlType' SqlString | ||
| Left (Just FTKeyCon) -> | ||
| SqlType' SqlString |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems extremely dubious to me
|
@erikd y'all wanna take a look at this? |
Before submitting your PR, check that you've:
@sincedeclarations to the HaddockAfter submitting your PR:
(unreleased)on the ChangelogContinuation of #1121
Fixes #957