I think the issue is that the res_id field in the attachment model is not being updated when attachment_ids are added before the record is saved.
res_id
attachment_ids