I'm writing a relational data model for a system which keeps track of a set of boxes rendered in a browser, each of which contains rendered images.
Currently, there is one table: Box. Each row has x and y coordinate, width and height columns, as well as columns for the type of image content (e.g. mime type) and content location (e.g. a file path or URL).
Some boxes have one layer of nesting - i.e. one box can contain another. In these cases the content type column has the special value 'box' and the location is a self-reference to the Box table.
Some content types (a minority) have extra values associated with the content type, e.g. if the image file is a more complicated multi-page format (e.g. PDF) then I need to store which page will be rendered in the box.
Can/should I represent this in one table? In this case, extra parameters could be stored (for example) as a query string in the file URL (/path/to/PDF.pdf?page=4).
How do I handle updating the self-referencing Box rows? i.e. If I delete a box which contains another box, then both rows should be deleted. I can't use a foreign key constraint on the location column, as it can either be a url (for non-nested boxes) or a Box row id (for nested boxes).