Suppose you have entities A, B, C and D.
Furthermore, user is only allowed to <
I'm not sure I understand what you want to achieve but can't you use option A, to verify if user is allowed to operate on D with only one access to the database?:
SELECT D.*
FROM D
JOIN C
ON C.id = D.cid
JOIN B
ON B.id = C.bid
JOIN A.id = B.aid
WHERE A.ownedBy = @userID
AND D.id = @idToBechecked
The obvious solution would be this: Given D, find C, then find B and eventually find A. If the chain breaks somewhere, access to D would be rejected. Unfortunately, this requires - if trivially implemented - 4 database accesses instead of just the one for A.
I suppose that might be possible. It depends in part on what "relates to" means, but assuming a relatively straightforward schema, I'd expect you to be able to join all four tables in a single SQL statement. If part of the chain is missing, the query would return no rows.
Or am I missing something?