That looks much better! But what about situation where user does not upload media file, but chooses from already uploaded posts instead? I think if it’s done via WordPress, then attachment record is cloned and then attached to new post_parent. Then your solution would break previous ties of existing attachment, wouldn’t it?