On 26/07/05, Berthold H=F6llmann <berthold@...> wrote:
> But each "Project" also has "Workpackage"s that have
> "Subproject"s. The "Workpackage"s and "Subproject"s have leader and
> deputy leaders that are "Person"s also. So where are the RelatedJoins in
> "Person" pointing to? To "Project", "Workpackage", or "Subproject"?
Wherever you tell them to point. e.g. RelatedJoin('Project') points to=20
Project relying on there being a RelatedJoin('Person') in Project for=20
symmetry.
Oh, you probably want to specify a joinColumn
If there is more than one column linking that table to this you can choose=
=20
which you want to join to by adding joinColumn=3D'Column' as an argument to=
=20
the join. e.g. see below. You don't need joinColumn if there is no=20
ambiguity.
I think I am right about these, I haven't actually had occasion to use one.
> The "Leader" in one "Workpackage" could be "Leader" for a "Subproject"
> also or "DeputyLeader" for another "Worpackage", or "Subproject". So
> it seems to me there is no easy way to model this depenedencies using
> SQLObject?
Sounds like a challenge! :-)
I hadn't mentioned joinColumn before.
These are only partial - I haven't put in all the relationships you would=
=20
need, but hopefully there are enough to show how it is done.
How about...?
class Project(SQLObject):
leader =3D ForeignKey('Person')
deputyLeader =3D ForeignKey('Person')
workers =3D RelatedJoin('Person')
class Workpackage(SQLobject):
parentProject =3D ForeignKey('Project')
subProjects =3D MultipleJoin('Subproject')
...
class Subproject(SQLObject):
parentWorkpackage =3D ForeignKey('Workpackage')
leader =3D ForeignKey('Person')
...
class Person(SQLObject):
leadsProjects =3D MultipleJoin('Project', joinColumn=3D'leader')
deputyLeadsProjects =3D MultipleJoin('Project', joinColumn=3D'deputyLeader'=
)
leadsSubprojects =3D MultipleJoin('Subproject')
worksForProjects =3D RelatedJoin('Project')
...
hopefully should be enough to see what is going on.
Here the related joins between Person and Project do not need to be told=20
their joinColumn, because they can only link to each other.
Or how about...?
class Project(SQLObject):
leader =3D ForeignKey('Person')
deputyLeader =3D ForeignKey('Person')
childProjects =3D MultipleJoin('Projects')
parentProject =3D ForeignKey('Projects')
class Person(SQLObject):
leadsProjects =3D MultipleJoin('Project', joinColumn=3D'leader')
deputyForProjects =3D MultipleJoin('Project', joinColumn=3D'deputyLeader')
Here, I have assumed that workpackages are actually much like projects,=20
(probably not a valid assumption, but for an example), so I did a couple of=
=20
joins to self in Project for the subproject relationships. The only=20
disadvantage is that in SQLObject there is no possibility of assigning Null=
=20
value for the parentProject foreign key. One workaround: you could make it=
=20
point to itself if there is no parent and then deal with itself turning up=
=20
among its childProjects. A bit ugly in this case.
Again, I hope this helps.
God bless,
John
|