Jump to content

Normalized many-to-many relation: Difference between revisions

From NusaATK
No edit summary
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 27: Line 27:


'''Be careful''' when using the AF_HIDE flag in the itermediate (A_B) node for the atkManyToOneRelation, in combination with multilanguage fields. When a relation is hidden, the key (a_id) will not be processed and no check on the language is done. This causes the added record to appear multiple times (once for every language), since a_id is not unique in the intermediate table.
'''Be careful''' when using the AF_HIDE flag in the itermediate (A_B) node for the atkManyToOneRelation, in combination with multilanguage fields. When a relation is hidden, the key (a_id) will not be processed and no check on the language is done. This causes the added record to appear multiple times (once for every language), since a_id is not unique in the intermediate table.
[[Category:Relations]]

Latest revision as of 10:13, 28 December 2006

A Many-To-Many-Relation basically consist of a atkOneToMany relation to the intermediate table. The intermediate node has two atkManyToOne relations defined.


Example

One person (node A) can have several skills (node B) and the same skill applies to more than one person.


If, in the example above, a skill is removed, this skill must be removed for all employees. This can be achieved by adding the AF_CASCADE_DELETE flag to the atkOneToManyRelation in node B:

atkOneToMany(“unique dummy”,
             “mymod.A_B”,
             “b_id”,
             AF_HIDE|AF_CASCADE_DELETE);

Normally you assign skills to a person (an not the other way round), so the atkOneToManyRelation in this node must be hidden.


And on the other hand, if an employee is deleted, the correspoding record(s) in the intermediate table must be removed as well.

atkOneToMany(“unique dummy”,
             “mymod.A_B”,
             “a_id”,
             AF_CASCADE_DELETE);

Be careful when using the AF_HIDE flag in the itermediate (A_B) node for the atkManyToOneRelation, in combination with multilanguage fields. When a relation is hidden, the key (a_id) will not be processed and no check on the language is done. This causes the added record to appear multiple times (once for every language), since a_id is not unique in the intermediate table.