Skip to content

Commit 22fe6fc

Browse files
committed
Preserve per-row ids in the SaveAutoIncrement std::vector overload
The std::vector compatibility wrapper copied into an fcpp::vector, ran the whole batch, then copied ids back at the end. Because each insert commits independently, a later row throwing would skip the end copy-back and leave the caller's std::vector without ids for rows that already committed. Save each record through the single-record overload instead, writing every id back as soon as its row is inserted - restoring the pre-fcpp::vector partial-success behavior and dropping the container copy. Addresses a Codex review comment on PR #39. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YLXHcZjrnrdhRZAgqDh6kd
1 parent 9c28890 commit 22fe6fc

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

‎include/database.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ class REFLECTION_EXPORT Database {
151151
}
152152
}
153153

154-
/// std::vector compatibility overload: copies into an fcpp::vector, forwards, and writes the
155-
/// generated ids back into the caller's std::vector.
154+
/// std::vector compatibility overload: saves each record through the single-record overload, so
155+
/// every generated id is written back into the caller's std::vector as soon as its row is
156+
/// inserted. This preserves the ids of already-committed rows if a later row in the batch fails
157+
/// (each insert commits independently), matching the pre-fcpp::vector behavior.
156158
template <typename T>
157159
void SaveAutoIncrement(std::vector<T>& models) {
158-
fcpp::vector<T> functional_models(models);
159-
SaveAutoIncrement(functional_models);
160-
for (size_t i = 0; i < models.size(); ++i) {
161-
models[i].id = functional_models[i].id;
160+
for (auto& model : models) {
161+
SaveAutoIncrement(model);
162162
}
163163
}
164164

0 commit comments

Comments
 (0)