Skip to content

Conversation

@robbassi
Copy link
Contributor

@robbassi robbassi commented Jan 8, 2020

This PR addresses issue #1009 for the PostgreSQL backend. In order to support multiple foreign keys on a single column, we now pass the reference name to getColumn, and use it in the where clause when querying foreign keys for the column.

Before submitting your PR, check that you've:

  • Bumped the version number

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

refMap = Map.fromList $ foldl ref [] cols
where ref rs c = case cReference c of
Nothing -> rs
(Just r) -> (unDBName $ cName c, r) : rs
Copy link
Contributor Author

@robbassi robbassi Jan 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we build a map of column names to foreign keys, so we can pass that on to getColumn.

,"AND kcu.table_name=? "
,"AND kcu.column_name=?"]
,"AND kcu.column_name=? "
,"AND tc.constraint_name=?"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now use the reference name to filter the query.

@robbassi
Copy link
Contributor Author

robbassi commented Jan 8, 2020

Tests seem to be failing for persistent-mongoDB, doesn't seem related to the changes in this PR though.

@MaxGabriel
Copy link
Member

@parsonsmatt
Copy link
Collaborator

Try merging master - there's an upper bound in place to prevent the cabal solver from picking that version.

@robbassi robbassi force-pushed the fix-migration-multiple-fk branch from 06fceec to feb00e6 Compare January 10, 2020 16:46
@robbassi
Copy link
Contributor Author

@parsonsmatt thanks!

Copy link
Collaborator

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me. Thanks!

, T.unpack (unDBName cname)
, " but got: "
, show xs
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ great error message!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That one is all @MaxGabriel

@MaxGabriel MaxGabriel merged commit c75890b into yesodweb:master Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants