Relations between dataΒΆ

Author:unknown
Version:unknown

dolmen.relations is a thin layer above zc.relation, allowing a simple and straightforward implementation of standalone relationships between objects.

Relationships are very important when you have objects in your application which reference other objects. Imagine you have an Employee object. Each Employee has an attribute “supervisor” which points to another Employee (or None).

You might want to perform miscellaneous queries on that. For example you might want to know all the employees supervised by a certain person. While you could just loop over all employees and check if the “supervisor” attribute matches the supervisor you want to query, this is going to be slow with many objects.

You also might want to perform more complex searches, like find the chain of control upwards from a certain employee.

All of this (and much more) can be done with dolmen.relations. To see how it is used check the README.txt in the dolmen.relation package.

Since dolmen.relation builds on zc.relation it inherits all of its power. I strongly recommend you to read the extensive zc.relation docs at http://pypi.python.org/pypi/zc.relation . They will show you all the queries that can be performed and expand on the Employee example from above. Take your time to reads these docs, it’s not the easiest topic, but it really pays off understanding relationships.