Hi, ich habe ein kleines Problem mit elixir
. Ich möchte Personen in Teams ordnen. Jedes Team hat genau einen Boss und jede Person genau ein Team (oder keins). Folgender Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #!/usr/bin/python from elixir import metadata, Entity, Field, Unicode, ManyToOne, \ using_options, setup_all, create_all metadata.bind = "sqlite:///foo.sqlite" metadata.bind.echo = True class Person(Entity): using_options(tablename="Person") name = Field(Unicode) team = ManyToOne("Team") class Team(Entity): using_options(tablename="Team") name = Field(Unicode) boss = ManyToOne("Person") setup_all() create_all() |
Hier kommt beim Ausführen sqlalchemy.exc.CircularDependencyError: Circular dependency detected: cycles: [...]
.
Mit Zwischentabelle:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #!/usr/bin/python from elixir import metadata, Entity, Field, Unicode, ManyToOne, \ using_options, setup_all, create_all metadata.bind = "sqlite:///foo.sqlite" metadata.bind.echo = True class Person(Entity): using_options(tablename="Person") name = Field(Unicode) class PersonTeam(Entity): using_options(tablename="PersonTeam") person = ManyToOne("Person") team = ManyToOne("Team") class Team(Entity): using_options(tablename="Team") name = Field(Unicode) boss = ManyToOne("Person") setup_all() create_all() |
Muss ich das über PersonTeam
machen?
LG Glocke