from sqlalchemy import Column, ForeignKey, Integer, Table
from sqlalchemy.orm import relationship

from great.models.core import Base, Model, Media


class Track(Media):
    __tablename__ = "tracks"

    number = Column(Integer)

    artists = relationship(
        "Artist", secondary="tracks_artists", lazy="dynamic",
    )

    composers = relationship(
        "Composer", secondary="tracks_composers", lazy="dynamic",
    )

    disc_id = Column(Integer, ForeignKey("discs.id"), nullable=True)


class Artist(Model):
    __tablename__ = "artists"


class Album(Media):
    __tablename__ = "albums"

    discs = relationship("Disc", backref="album", lazy="dynamic")


class Disc(Media):
    __tablename__ = "discs"

    number = Column(Integer)

    tracks = relationship("Track", backref="disc")

    album_id = Column(Integer, ForeignKey("albums.id"))


class Composer(Model):
    __tablename__ = "composers"


Table(
    "tracks_artists",
    Base.metadata,
    Column("track_id", Integer, ForeignKey("tracks.id")),
    Column("artist_id", Integer, ForeignKey("artists.id")),
)

Table(
    "tracks_composers",
    Base.metadata,
    Column("track_id", Integer, ForeignKey("tracks.id")),
    Column("composer_id", Integer, ForeignKey("composers.id")),
)

@@ -227,208 +227,8 @@
 r)%0A%0A
-    artists = relationship(%0A        %22Artist%22, secondary=%22tracks_artists%22, lazy=%22dynamic%22,%0A    )%0A%0A    composers = relationship(%0A        %22Composer%22, secondary=%22tracks_composers%22, lazy=%22dynamic%22,%0A    )%0A%0A
     
@@ -346,16 +346,129 @@
 tists%22%0A%0A
+    tracks = relationship(%0A        %22Track%22, backref=%22artists%22, secondary=%22tracks_artists%22, lazy=%22dynamic%22,%0A    )%0A
 %0Aclass A
@@ -822,16 +822,158 @@
 osers%22%0A%0A
+    tracks = relationship(%0A        %22Track%22,%0A        backref=%22composers%22,%0A        secondary=%22tracks_composers%22,%0A        lazy=%22dynamic%22,%0A    )%0A%0A
 %0ATable(%0A

Fix lazy loading.