shutro 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -354,6 +354,27 @@ export async function createRecords(host, model, input, options = {}) {
|
|
|
354
354
|
for (const parent of new Set(parents))
|
|
355
355
|
invalidateInverseLists(host, model, key, null, parent);
|
|
356
356
|
}
|
|
357
|
+
// A computed field with an inverse is writable on create too (Kosh request #36): its given value is cached and
|
|
358
|
+
// the inverse runs for the records that gave it, as on write; the compute still runs at the flush point and
|
|
359
|
+
// should agree with what the inverse wrote.
|
|
360
|
+
const inverted = new Map();
|
|
361
|
+
prepared.forEach((p, i) => {
|
|
362
|
+
for (const [key, value] of p.stored) {
|
|
363
|
+
const field = model.fields[key];
|
|
364
|
+
if (!field.computed || field.inverse === undefined)
|
|
365
|
+
continue;
|
|
366
|
+
// Only what the caller gave (a compute's own key may be prepared with nothing given).
|
|
367
|
+
const row = input[i];
|
|
368
|
+
if (row === undefined || row[key] === undefined)
|
|
369
|
+
continue;
|
|
370
|
+
host.values(model.name, ids[i], true).set(key, value);
|
|
371
|
+
inverted.set(key, [...(inverted.get(key) ?? []), ids[i]]);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
for (const [key, withValue] of inverted) {
|
|
375
|
+
const inverse = model.fields[key].inverse;
|
|
376
|
+
await inverse(host.recordset(model, withValue), key);
|
|
377
|
+
}
|
|
357
378
|
for (const f of internals.registry.compute.stored(model.name))
|
|
358
379
|
internals.markToCompute(model.name, f.key, ids);
|
|
359
380
|
// one2many `create` commands of every new parent become one child insert per field (no INSERT per parent).
|
package/package.json
CHANGED