Show referring tables and rows when the referring foreign key is compound#2003
Show referring tables and rows when the referring foreign key is compound#2003fgregg wants to merge 4 commits intosimonw:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2003 +/- ##
==========================================
+ Coverage 92.11% 92.12% +0.01%
==========================================
Files 38 38
Lines 5555 5565 +10
==========================================
+ Hits 5117 5127 +10
Misses 438 438 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| foreign_key | ||
| for foreign_key in foreign_keys | ||
| if foreign_key["column"] == column | ||
| if foreign_key["columns"][0] == column |
There was a problem hiding this comment.
because we don't have a strong idea of how to display compound foreign keys in a table view, we have to do this operation in a few places.
| "other_table": "roadside_attraction_characteristics", | ||
| "column": "pk", | ||
| "other_column": "characteristic_id", | ||
| "columns": ["pk"], |
There was a problem hiding this comment.
this is how the API changes.
| "other_columns": ["foreign_key_with_blank_label"], | ||
| "count": 0, | ||
| "link": "/fixtures/foreign_key_references?foreign_key_with_blank_label=1", | ||
| "other_columns_reference": "foreign_key_with_blank_label", |
There was a problem hiding this comment.
this is also another API change. this got introduced so we could have compound keys look good in the row template, but we could do that through a custom filter instead.
|
@simonw, let me know what you think about this approach! |
|
see this related discussion to a change in API in sqlite-utils simonw/sqlite-utils#203 (comment) |
sqlite foreign keys can be compound, but that is not as well supported by datasette as single column foreign keys.
in particular,
Both of these issues are discussed in #1099.
This PR only fixes the second one, because it's not clear what the right UX is for the first issue.
Some things that might not be desirable about this approach.
column=>columnsandother_column=>other_columns(see inline comment for more discussion.