I have a table like this:
Attribute | Type | Modifier
------------+---------+----------
id | integer | not null
title | text | not null
parent | integer |
The parent
field is a foreign key referencing the same table.
How can I ensure that no loops (circular parent/child references) are ever inserted? For example:
id | title | parent
------------+---------+----------
1 | A | 3 or 2
2 | B | 1
3 | C | 2
I'm using PHP and MySQL.