Avoid updating same record twice when updating record on m2m table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 06:42 AM
Hi All,
I am writing a fix script to update records on the m2m table. Since its m2m relationship one record has multiple records linked to it(just like sys_user_has_role table).So, Whenever i am updating something it is updating the same record multiple times. How can i avoid this?
Thanks
Vidyashree
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 10:24 AM
The issue is caused because the updateWithReferences() method is being called within a loop for each m2m record, potentially leading to multiple updates on the same sn_vul_vulnerable_item record if it is linked to multiple m2m records.
To avoid this, you need to ensure that each sn_vul_vulnerable_item record is updated only once. You can achieve this by maintaining a set of already processed sys_ids for the sn_vul_vulnerable_item records.