-
Notifications
You must be signed in to change notification settings - Fork 100
Open
Description
Discussed in #683
Originally posted by Drapersniper November 21, 2022
class Track(Table):
track_id = BigInt(primary_key=True)
class Playlist(Table):
id = BigInt(primary_key=True)
tracks = M2M(LazyTableReference("TrackToPlaylist", module_path=__module__))
class Album(Table):
id = BigInt(primary_key=True)
tracks = M2M(LazyTableReference("TrackToAlbum", module_path=__module__))
class TrackToPlaylist(Table):
tracks = ForeignKey(Track)
playlists= ForeignKey(Playlist)
class TrackToAlbum(Table):
tracks = ForeignKey(Track)
albums= ForeignKey(Album)
# Step 1 - I expect this to work fine if this is the first time the tracks with id 0-9 are being added to the db
playlist = await Playlist.objects().get_or_create(Playlist.id == 1)
tracks = [Track(track_id=i) for i in range(10)]
await playlist.add_m2m(*tracks, m2m=Playlist.tracks)
# Step 2 - After step 1 do the following
playlist2 = await Playlist.objects().get_or_create(Playlist.id == 2)
tracks2 = [Track(track_id=i) for i in range(5)]
await playlist2 .add_m2m(*tracks2, m2m=Playlist.tracks)
# Step 3
playlist3 = await Playlist.objects().get_or_create(Playlist.id == 3)
tracks3 = [Track(track_id=i) for i in range(5)]
tracks3 += [Track(track_id=i) for i in range(5)]
await playlist3 .add_m2m(*tracks3, m2m=Playlist.tracks)
# Step 4 - Run after step 1
album = await Album.objects().get_or_create(Album.id == 1)
tracks4 = [Track(track_id=i) for i in range(5)]
await album .add_m2m(*tracks4, m2m=Album.tracks)What is expected to happen after steps 2, 3, and 4?
Currently it raises an exception
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels