@omnifyjp/ts 3.21.0 → 3.21.2
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.
|
@@ -1250,7 +1250,13 @@ ${lookupExample}
|
|
|
1250
1250
|
|
|
1251
1251
|
${filterBlock}${softDeleteBlock}${limitBlock}
|
|
1252
1252
|
|
|
1253
|
-
|
|
1253
|
+
// #76 followup (v3.21.2): use getAttributes() to bypass Astrotomic's
|
|
1254
|
+
// Translatable::attributesToArray() override, which would overwrite
|
|
1255
|
+
// our COALESCE'd translatable columns with its own locale fallback
|
|
1256
|
+
// resolution (use_property_fallback-gated, default off). getAttributes()
|
|
1257
|
+
// returns the raw DB-column → value map as Eloquent populated it from
|
|
1258
|
+
// the SELECT, preserving our carefully crafted locale-aware values.
|
|
1259
|
+
return $query->get()->map(fn ($row) => $row->getAttributes())->toArray();
|
|
1254
1260
|
}`;
|
|
1255
1261
|
}
|
|
1256
1262
|
// #76: translatable branch — leftJoin the sidecar keyed by
|
|
@@ -1320,7 +1326,13 @@ ${lookupExample}
|
|
|
1320
1326
|
|
|
1321
1327
|
${filterBlock}${softDeleteBlock}${limitBlock}
|
|
1322
1328
|
|
|
1323
|
-
|
|
1329
|
+
// #76 followup (v3.21.2): use getAttributes() to bypass Astrotomic's
|
|
1330
|
+
// Translatable::attributesToArray() override, which would overwrite
|
|
1331
|
+
// our COALESCE'd translatable columns with its own locale fallback
|
|
1332
|
+
// resolution (use_property_fallback-gated, default off). getAttributes()
|
|
1333
|
+
// returns the raw DB-column → value map as Eloquent populated it from
|
|
1334
|
+
// the SELECT, preserving our carefully crafted locale-aware values.
|
|
1335
|
+
return $query->get()->map(fn ($row) => $row->getAttributes())->toArray();
|
|
1324
1336
|
}`;
|
|
1325
1337
|
}
|
|
1326
1338
|
// ── flushTranslations() ────────────────────────────────────────────────────
|
|
@@ -1334,6 +1346,15 @@ function buildFlushTranslationsMethod(modelName) {
|
|
|
1334
1346
|
// Model::withoutEvents(...) that hook doesn't fire. Walking the collection
|
|
1335
1347
|
// and calling save() on dirty rows makes the persistence path explicit and
|
|
1336
1348
|
// seeder-safe.
|
|
1349
|
+
//
|
|
1350
|
+
// #78 Step 3 followup (v3.21.1): mirror Astrotomic's own saveTranslations()
|
|
1351
|
+
// FK-assignment step (Translatable::saveTranslations:382-401) — when the
|
|
1352
|
+
// parent row is created via Model::create() inside WithoutModelEvents, the
|
|
1353
|
+
// new translation models are queued before the parent INSERT runs, so the
|
|
1354
|
+
// belongsTo backref never fires. We must explicitly stamp the FK from the
|
|
1355
|
+
// saved parent before calling $translation->save() or MySQL rejects the
|
|
1356
|
+
// row with "Column 'product_id' cannot be null". Same applies to the
|
|
1357
|
+
// connection name for multi-connection projects.
|
|
1337
1358
|
return `
|
|
1338
1359
|
/**
|
|
1339
1360
|
* Persist pending translation rows (seeder-safe).
|
|
@@ -1344,15 +1365,27 @@ function buildFlushTranslationsMethod(modelName) {
|
|
|
1344
1365
|
* models queued on \\$model->translations. Astrotomic's own \`saved\` event
|
|
1345
1366
|
* hook flushes them at runtime — but that hook is suppressed under
|
|
1346
1367
|
* DatabaseSeeder::WithoutModelEvents or any call to Model::withoutEvents.
|
|
1347
|
-
* This helper walks the collection and saves dirty/new rows explicitly
|
|
1348
|
-
*
|
|
1368
|
+
* This helper walks the collection and saves dirty/new rows explicitly
|
|
1369
|
+
* (mirroring Astrotomic's own saveTranslations()) so both runtime and
|
|
1370
|
+
* seeder paths write to the sidecar table.
|
|
1349
1371
|
*
|
|
1350
|
-
* @see https://github.com/Astrotomic/laravel-translatable/blob/main/src/Translatable/Translatable.php Translatable::
|
|
1372
|
+
* @see https://github.com/Astrotomic/laravel-translatable/blob/main/src/Translatable/Translatable.php Translatable::saveTranslations()
|
|
1351
1373
|
*/
|
|
1352
1374
|
protected function flushTranslations(${modelName} $model): void
|
|
1353
1375
|
{
|
|
1354
1376
|
foreach ($model->translations as $translation) {
|
|
1355
1377
|
if (! $translation->exists || $translation->isDirty()) {
|
|
1378
|
+
// Mirror Astrotomic\\Translatable\\Translatable::saveTranslations() —
|
|
1379
|
+
// explicitly stamp the FK and (when set) the connection so the
|
|
1380
|
+
// save works even inside Model::withoutEvents(), where the
|
|
1381
|
+
// belongsTo backref never fires.
|
|
1382
|
+
if (! empty($connectionName = $model->getConnectionName())) {
|
|
1383
|
+
$translation->setConnection($connectionName);
|
|
1384
|
+
}
|
|
1385
|
+
$translation->setAttribute(
|
|
1386
|
+
$model->getTranslationRelationKey(),
|
|
1387
|
+
$model->getKey()
|
|
1388
|
+
);
|
|
1356
1389
|
$translation->save();
|
|
1357
1390
|
}
|
|
1358
1391
|
}
|