-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make reverse work multiple levels deep
- Loading branch information
1 parent
cf4ffc1
commit 216907f
Showing
7 changed files
with
110 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,56 @@ | ||
from piccolo.columns import ForeignKey, Text, Varchar | ||
from piccolo.table import Table | ||
from tests.base import TableTest | ||
|
||
|
||
class Band(Table): | ||
name = Varchar() | ||
|
||
|
||
class FanClub(Table): | ||
address = Text() | ||
band = ForeignKey(Band, unique=True) | ||
|
||
|
||
class Treasurer(Table): | ||
name = Varchar() | ||
fan_club = ForeignKey(FanClub, unique=True) | ||
|
||
|
||
class TestReverse(TableTest): | ||
tables = [Band, FanClub, Treasurer] | ||
|
||
def setUp(self): | ||
super().setUp() | ||
|
||
band = Band({Band.name: "Pythonistas"}) | ||
band.save().run_sync() | ||
|
||
fan_club = FanClub( | ||
{FanClub.band: band, FanClub.address: "1 Flying Circus, UK"} | ||
) | ||
fan_club.save().run_sync() | ||
|
||
treasurer = Treasurer( | ||
{Treasurer.fan_club: fan_club, Treasurer.name: "Bob"} | ||
) | ||
treasurer.save().run_sync() | ||
|
||
def test_reverse(self): | ||
response = Band.select( | ||
Band.name, | ||
FanClub.band.reverse().address.as_alias("address"), | ||
Treasurer.fan_club._.band.reverse().name.as_alias( | ||
"treasurer_name" | ||
), | ||
).run_sync() | ||
self.assertListEqual( | ||
response, | ||
[ | ||
{ | ||
"name": "Pythonistas", | ||
"address": "1 Flying Circus, UK", | ||
"treasurer_name": "Bob", | ||
} | ||
], | ||
) |
This file contains 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 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 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