Reduce number of queries in ModelSQL.write
Currently, we make a select to check if the ids are accessible ('write_error') inside a loop of actions. This query could be done once for the sum of all records (using grouped_slice). This will make the write operation linear with a factor of 1 query instead of 2 queries.