ATK Relations: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
A relation defines a relation between two tables. One or more records in the first table belong to one or more records in the second table. A one to many relation would be '1 library has N books'. | |||
= atkOneToOneRelation = | = atkOneToOneRelation = | ||
An atkOneToOneRelation defines a relation between two tables where there is one record in the first table that belongs to one record in the second table. | |||
The atkOneToOneRelation supports two configurations: master mode and slave mode. The mode to use is detected automatically based on the value of the $refKey parameter. | The atkOneToOneRelation supports two configurations: master mode and slave mode. The mode to use is detected automatically based on the value of the $refKey parameter. | ||
| Line 15: | Line 19: | ||
Referential key a_id is in the other node, so this is the master-configuration. | Referential key a_id is in the other node, so this is the master-configuration. | ||
== Slave mode == | == Slave mode example == | ||
The node in which the relation is implemented (code is in node B), is considered the child. And the referential key pointing to the master record (a_id) is in the current node (node B). | The node in which the relation is implemented (code is in node B), is considered the child. And the referential key pointing to the master record (a_id) is in the current node (node B). | ||
| Line 23: | Line 27: | ||
= atkOneToManyRelation = | = atkOneToManyRelation = | ||
Suppose a department (node A) has many employees (node B). To edit the list of employees in a department, this relationship can be built with an atkOneToManyRelation. Each employee gets a department_id (a_id). | |||
[[image:atkOneToMany.jpg|center]] | |||
= atkManyToOneRelation = | = atkManyToOneRelation = | ||
[[image:atkManyToOne.jpg|center]] | |||
Revision as of 12:36, 14 July 2006
A relation defines a relation between two tables. One or more records in the first table belong to one or more records in the second table. A one to many relation would be '1 library has N books'.
atkOneToOneRelation
An atkOneToOneRelation defines a relation between two tables where there is one record in the first table that belongs to one record in the second table.
The atkOneToOneRelation supports two configurations: master mode and slave mode. The mode to use is detected automatically based on the value of the $refKey parameter.
function atkOneToOneRelation($name, $destination, $refKey="", $flags=0)
- $name: The unique name of the attribute.
- $destination: the destination node (in module.nodename notation)
- $refKey: foreign-key field (master mode) or empty (slave mode)
Master mode example
The node in which the relation is implemented, is considered the master (code is in node A). And the referential key pointing to the master record (a_id) is in the destination node (node B).

Referential key a_id is in the other node, so this is the master-configuration.
Slave mode example
The node in which the relation is implemented (code is in node B), is considered the child. And the referential key pointing to the master record (a_id) is in the current node (node B).

Referential key a_id is in the same node, so this is the slave-configuration.
atkOneToManyRelation
Suppose a department (node A) has many employees (node B). To edit the list of employees in a department, this relationship can be built with an atkOneToManyRelation. Each employee gets a department_id (a_id).

atkManyToOneRelation
