datasette icon indicating copy to clipboard operation
datasette copied to clipboard

Show referring tables and rows when the referring foreign key is compound

Open fgregg opened this issue 2 years ago • 3 comments

sqlite foreign keys can be compound, but that is not as well supported by datasette as single column foreign keys.

in particular,

  1. in a table view, there is not a link from the row to the referenced row if the foreign key is compound
  2. in a row view, there is no listing of tables and rows that refer to the focal row if those referencing foreign keys are compound.

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.

Screenshot 2023-01-24 at 19-47-40 nlrb bargaining_unit

Some things that might not be desirable about this approach.

  1. it changes the external API, by changing column => columns and other_column => other_columns (see inline comment for more discussion.
  2. There are various places where the plural foreign keys have to be checked for length and discarded or transformed to singular.

fgregg avatar Jan 24 '23 21:01 fgregg

Codecov Report

Base: 92.11% // Head: 92.12% // Increases project coverage by +0.01% :tada:

Coverage data is based on head (1e5b42f) compared to base (e4ebef0). Patch coverage: 100.00% of modified lines in pull request are covered.

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              
Impacted Files Coverage Δ
datasette/app.py 94.50% <100.00%> (+0.01%) :arrow_up:
datasette/filters.py 95.73% <100.00%> (+0.04%) :arrow_up:
datasette/utils/__init__.py 94.89% <100.00%> (+0.02%) :arrow_up:
datasette/views/row.py 87.82% <100.00%> (ø)
datasette/views/table.py 92.61% <100.00%> (+0.03%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar Jan 25 '23 00:01 codecov[bot]

@simonw, let me know what you think about this approach!

fgregg avatar Jan 25 '23 00:01 fgregg

see this related discussion to a change in API in sqlite-utils https://github.com/simonw/sqlite-utils/pull/203#issuecomment-753567932

fgregg avatar Jan 25 '23 18:01 fgregg