There are 3 tables - records ( items ), pages ( pages ) and images ( images ). The image table stores the paths to the image files. The problem is how to organize the structure. Those. I had to create the owner_type field and sample by this condition, i.e. like this
SELECT * FROM images WHERE owner_id = id AND owner_type = 'item' because Record id and page can match and the image will be overwritten or at least get what you need. Simplified table of images looks like this
images ------------------------- id | owner_id | owner_type Accordingly, the owner_type just gets a string or 'page' or 'item'. Actually the question is how to get rid of this owner_type ?