@omnifyjp/omnify 3.21.0 → 3.21.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnifyjp/omnify",
3
- "version": "3.21.0",
3
+ "version": "3.21.1",
4
4
  "description": "Schema-driven code generation for Laravel, TypeScript, and SQL",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -36,10 +36,10 @@
36
36
  "zod": "^3.24.0"
37
37
  },
38
38
  "optionalDependencies": {
39
- "@omnifyjp/omnify-darwin-arm64": "3.21.0",
40
- "@omnifyjp/omnify-darwin-x64": "3.21.0",
41
- "@omnifyjp/omnify-linux-x64": "3.21.0",
42
- "@omnifyjp/omnify-linux-arm64": "3.21.0",
43
- "@omnifyjp/omnify-win32-x64": "3.21.0"
39
+ "@omnifyjp/omnify-darwin-arm64": "3.21.1",
40
+ "@omnifyjp/omnify-darwin-x64": "3.21.1",
41
+ "@omnifyjp/omnify-linux-x64": "3.21.1",
42
+ "@omnifyjp/omnify-linux-arm64": "3.21.1",
43
+ "@omnifyjp/omnify-win32-x64": "3.21.1"
44
44
  }
45
45
  }
@@ -1334,6 +1334,15 @@ function buildFlushTranslationsMethod(modelName) {
1334
1334
  // Model::withoutEvents(...) that hook doesn't fire. Walking the collection
1335
1335
  // and calling save() on dirty rows makes the persistence path explicit and
1336
1336
  // seeder-safe.
1337
+ //
1338
+ // #78 Step 3 followup (v3.21.1): mirror Astrotomic's own saveTranslations()
1339
+ // FK-assignment step (Translatable::saveTranslations:382-401) — when the
1340
+ // parent row is created via Model::create() inside WithoutModelEvents, the
1341
+ // new translation models are queued before the parent INSERT runs, so the
1342
+ // belongsTo backref never fires. We must explicitly stamp the FK from the
1343
+ // saved parent before calling $translation->save() or MySQL rejects the
1344
+ // row with "Column 'product_id' cannot be null". Same applies to the
1345
+ // connection name for multi-connection projects.
1337
1346
  return `
1338
1347
  /**
1339
1348
  * Persist pending translation rows (seeder-safe).
@@ -1344,15 +1353,27 @@ function buildFlushTranslationsMethod(modelName) {
1344
1353
  * models queued on \\$model->translations. Astrotomic's own \`saved\` event
1345
1354
  * hook flushes them at runtime — but that hook is suppressed under
1346
1355
  * DatabaseSeeder::WithoutModelEvents or any call to Model::withoutEvents.
1347
- * This helper walks the collection and saves dirty/new rows explicitly so
1348
- * both runtime and seeder paths write to the sidecar table.
1356
+ * This helper walks the collection and saves dirty/new rows explicitly
1357
+ * (mirroring Astrotomic's own saveTranslations()) so both runtime and
1358
+ * seeder paths write to the sidecar table.
1349
1359
  *
1350
- * @see https://github.com/Astrotomic/laravel-translatable/blob/main/src/Translatable/Translatable.php Translatable::fill()
1360
+ * @see https://github.com/Astrotomic/laravel-translatable/blob/main/src/Translatable/Translatable.php Translatable::saveTranslations()
1351
1361
  */
1352
1362
  protected function flushTranslations(${modelName} $model): void
1353
1363
  {
1354
1364
  foreach ($model->translations as $translation) {
1355
1365
  if (! $translation->exists || $translation->isDirty()) {
1366
+ // Mirror Astrotomic\\Translatable\\Translatable::saveTranslations() —
1367
+ // explicitly stamp the FK and (when set) the connection so the
1368
+ // save works even inside Model::withoutEvents(), where the
1369
+ // belongsTo backref never fires.
1370
+ if (! empty($connectionName = $model->getConnectionName())) {
1371
+ $translation->setConnection($connectionName);
1372
+ }
1373
+ $translation->setAttribute(
1374
+ $model->getTranslationRelationKey(),
1375
+ $model->getKey()
1376
+ );
1356
1377
  $translation->save();
1357
1378
  }
1358
1379
  }