-
Notifications
You must be signed in to change notification settings - Fork 26
changes to support non-primary key in Piccolo Admin #134
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6df9c07
changes to support non-primary key in Piccolo Admin
sinisaos d899cd1
fix for multiple reference non primary keys
sinisaos 1d9b3b2
fix filter search
sinisaos b7e402d
correct type for Postgres
sinisaos 346f3ee
cleaning and renaming variables
sinisaos a828396
final fix for multiple non-primary key per table
sinisaos a6f2cca
index moved to target_column_fk_name
sinisaos c94facb
Merge branch 'master' into reference_non_primary_key
sinisaos ac16f2b
fix linter errors
sinisaos 2c0a351
Merge branch 'piccolo-orm:master' into reference_non_primary_key
sinisaos 2cd11bb
Merge branch 'piccolo-orm:master' into reference_non_primary_key
sinisaos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| from unittest import TestCase | ||
|
|
||
| from piccolo.columns.column_types import ForeignKey, Varchar | ||
| from piccolo.table import Table | ||
| from starlette.testclient import TestClient | ||
|
|
||
| from piccolo_api.crud.endpoints import PiccoloCRUD | ||
|
|
||
|
|
||
| class Serie(Table): | ||
| name = Varchar(length=100, unique=True) | ||
|
|
||
|
|
||
| class Review(Table): | ||
| reviewer = Varchar() | ||
| serie = ForeignKey(Serie, target_column=Serie.name) | ||
|
|
||
|
|
||
| class TestTargetPK(TestCase): | ||
| """ | ||
| Make sure PiccoloCRUD works with Tables with a non-primary key column. | ||
| """ | ||
|
|
||
| def setUp(self): | ||
| Serie.create_table(if_not_exists=True).run_sync() | ||
| Review.create_table(if_not_exists=True).run_sync() | ||
|
|
||
| def tearDown(self): | ||
| Review.alter().drop_table().run_sync() | ||
| Serie.alter().drop_table().run_sync() | ||
|
|
||
| def test_target_column_pk(self): | ||
| Serie(name="Devs").save().run_sync() | ||
| Review(reviewer="John Doe", serie="Devs").save().run_sync() | ||
|
|
||
| review = Review.select(Review.serie.id).first().run_sync() | ||
|
|
||
| self.client = TestClient(PiccoloCRUD(table=Serie, read_only=False)) | ||
| response = self.client.get("/Devs/") | ||
| self.assertEqual(response.status_code, 200) | ||
| self.assertEqual(response.json()["id"], review["serie.id"]) | ||
|
|
||
| self.client = TestClient(PiccoloCRUD(table=Review, read_only=False)) | ||
| response = self.client.get( | ||
| "/", params={"serie": f"{review['serie.id']}"} | ||
| ) | ||
| self.assertEqual(response.status_code, 200) | ||
| self.assertEqual( | ||
| response.json(), | ||
| {"rows": [{"id": 1, "reviewer": "John Doe", "serie": "Devs"}]}, | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we can move the logic around a bit here.
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.
Unfortunately this also does not work if we have multiple non-primary keys per single table. e.g if we add director name as non-primary key (or mix primary or non-primary keys) to review reviewer this does not work. we should to leave this as is.