CMS article insert/update (chiangmai, where-else): store sub_category_ids as strict CSV ('15,21' not '15, 21') so FIND_IN_SET matches every chosen sub-category, not just the first; migration strips spaces from existing rows
This commit is contained in:
1 parent
fdb71d61c7
commit
e95006a9e9
1 file changed
+22
+22
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
// Article insert/update used to store sub_category_ids as "15, 21" (comma+space).
|
||||||
|
// Every reader uses FIND_IN_SET(?, sub_category_ids), which never matches " 21",
|
||||||
|
// so only the first checked sub-category was ever visible. Strip the spaces.
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
DB::table('article')
|
||||||
|
->where('sub_category_ids', 'like', '% %')
|
||||||
|
->update(['sub_category_ids' => DB::raw("REPLACE(sub_category_ids, ' ', '')")]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
// Irreversible by design: the spaced format was a bug, not a schema.
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in new issue
Block a user