SELECT
'accounts'.'id' AS id_0,
'accounts'.'child_id' AS child_id_0,
'child_accounts_1'.'id' AS id_1,
'child_accounts_1'.'child_id' AS child_id_1,
'child_accounts_2'.'id' AS id_2,
'child_accounts_2'.'child_id' AS child_id_2,
'child_accounts_3'.'id' AS id_3,
'child_accounts_3'.'child_id' AS child_id_3,
'child_accounts_4'.'id' AS id_4,
'child_accounts_4'.'child_id' AS child_id_4
FROM
'accounts'
LEFT OUTER JOIN 'accounts' 'child_accounts_1'
ON 'child_accounts_1'.'id' = 'accounts'.'child_id'
LEFT OUTER JOIN 'accounts' 'child_accounts_2'
ON 'child_accounts_2'.'id' = 'child_accounts_1'.'child_id'
LEFT OUTER JOIN 'accounts' 'child_accounts_3'
ON 'child_accounts_3'.'id' = 'child_accounts_2'.'child_id'
LEFT OUTER JOIN 'accounts' 'child_accounts_4'
ON 'child_accounts_4'.'id' = 'child_accounts_3'.'child_id'
WHERE 'accounts'.'id' = 56
, , - .
accounts negative_overflow_account_id, . "id" "negative_overflow_id" 5 .
, MAX_OVERFLOW, "5", /, .
Basically, my use case was to make sure that someone does not set up an infinitely circular loop, so if he reaches level 5, then the user receives an error telling them that they cannot set it so deep. And if any of the levels refers to the upper level or to one of the previous levels, then an error is also generated that indicates circular recursion (which may lead to the application crashing later if it is allowed to continue).
EDIT: I shortened the names. nobody wants to see my stupid ridiculous naming convention for this stupid table;)
source
share