Jump to content

AtkOneToManyRelation

From NusaATK
Revision as of 21:53, 18 August 2008 by bahtiar (talk | contribs)
atkOneToManyRelation screenshot

atkOneToManyRelation

function atkOneToManyRelation($name, $destination, $refKey="", $flags=0)
  • $name The unique name of this relation within a node - In contrast with moth other attributes, the name does not correspond to a database field. This is because in one2many relations, the databasefield that stores the link, is in the destination node (B) and not in the owner node (A)
  • $destination The node to which the relationship is made
  • $refKey For regular oneToMany relationships, $refKey is name of the referential key in the destination node. In the case of multi-foreign key relationships, $refKey can be an array of fields.


Example

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).


It is possible to use setDestinationFilter() on this relation. This can be helpful in creating table links that depend on another field.

Example

 $rel = &new atkOneToManyRelation("notes","node.notes","note_related_id", AF_HIDE_LIST);
 $rel->setDestinationFilter("type='employees'");
 $this->add($rel);

This should also auto populate the filter when adding sub nodes.

note that setDestinationFilter("type='employees'"); works but setDestinationFilter("type = 'employees'"); does not appear to work as it will add the single quotes into the field which wont be seen since they aren't in the filter.