The inner arrays must contain the keys,
idfield, name, joinfield, and label. idfield is the name of the primary key in
the related table. name is the name of the related table. joinfield is the name of the
foreign key in the related table. label is the description of the relationship to use in
the error message if any dependencies are found.
Imagine that there is another table called #__myextension_children; this table has
a primary key called childid and a foreign key called parent, which is related to
the primary key field id in #__myextension_foobars. In this example, we verify
there are no dependent records in the #__myextension_children table before
deleting a record from #__myextension_foobars.
$join1 = array('idfield' => 'childid',
'name' => '#__myextension_children',
'joinfield' => 'parent',
'label' => 'Children');
The Database
[ 58 ]
$joins = array($join1);
if ($table->canDelete($id, $joins))
{
if (!$table->delete($id))
{
// handle failed delete
// use $table->getError() for an explanation
}
}
else
{
// handle dependent records, cannot delete
// use $table->getError() for an explanation
}
We can define more than one join, for example had there been another table called
#__myextension_illegitimate_children we could also have defined this in the
$joins array.
Pages:
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90