In this "How To", you will learn to create a One-to-One Relationship, a One-to-Many Relationship, a Many-to-Many Relationship, and finally a One-to-Many Container Relationship.
Example of 1:1 Server to Admin Relationship
... from Products.ZenRelations.RelSchema import *... class Server(Device): ... _relations = (
("admin"
, ToOne(ToOne, "Admin", "server")
), ) + Device._relations ... ... class Admin(TestBaseClass): ... _relations = ( ("server", ToOne(ToOne, "Server", "admin")),
) ... ... ...
The Server object is an example of a class that inherits from Device. According to this relationship there can be only one Admin assigned to a Server and only one Server assigned to an Admin. This relationship is created by:
Importing ToOne from Products.ZenRelations.RelSchema. |
|
Appending a two-item tuple to the _relations attribute |
|
The first item in the tuple is a "string" object which is the local name |
|
The second item in the tuple is a "RelSchema" object which represents the relationship to another class. In this case the ToOne constructor creates/returns that "RelSchema" object ToOne constructors takes three parameters:
|
|
Appending a complementary two item tuple to the _relations attribute in the relative class. |