robinNcode / db_craft

DB Craft - CodeIgniter 4 Seeder, Migration Generator
15 stars 3 forks source link

CI4.5.1 Array to string conversion at MigrationGenerator.php:266 #5

Closed AnwarQasem closed 3 months ago

AnwarQasem commented 4 months ago

Hey guys, great library ... I just had a small issue with it.

php spark get:migration cards

CodeIgniter v4.5.1 Command Line Tool - Server Time: 2024-05-12 04:00:25 UTC+03:00

[ErrorException]
Array to string conversion
at VENDORPATH\robinncode\db_craft\src\Libraries\MigrationGenerator.php:266

Backtrace:
  1    VENDORPATH\robinncode\db_craft\src\Libraries\MigrationGenerator.php:266
       CodeIgniter\Debug\Exceptions()->errorHandler(2, 'Array to string conversion', '\\vendor\\robinncode\\db_craft\\src\\Libraries\\MigrationGenerator.php', 266)

  2    VENDORPATH\robinncode\db_craft\src\Libraries\MigrationGenerator.php:99
       Robinncode\DbCraft\Libraries\MigrationGenerator()->generateForeignKeys('cards')

  3    VENDORPATH\robinncode\db_craft\src\Libraries\MigrationGenerator.php:60
       Robinncode\DbCraft\Libraries\MigrationGenerator()->getTableInfos('cards')

  4    VENDORPATH\robinncode\db_craft\src\Commands\GetMigrationCommand.php:22
       Robinncode\DbCraft\Libraries\MigrationGenerator()->generateSingleMigration('cards')

  5    SYSTEMPATH\CLI\Commands.php:70
       Robinncode\DbCraft\Commands\GetMigrationCommand()->run([])

  6    SYSTEMPATH\CLI\Console.php:48
       CodeIgniter\CLI\Commands()->run('get:migration', [...])

  7    SYSTEMPATH\Boot.php:338
       CodeIgniter\CLI\Console()->run()

  8    SYSTEMPATH\Boot.php:104
       CodeIgniter\Boot::runCommand(Object(CodeIgniter\CLI\Console))

  9    ROOTPATH\spark:84
       CodeIgniter\Boot::bootSpark(Object(Config\Paths))

I've fixed it by adding in MigrationGenerator.php instead of:

 foreach ($keys as $key)
            $keyArray[] = "\n\t\t\$this->forge->addForeignKey('$key->column_name','$key->foreign_table_name','$key->column_name','CASCADE','CASCADE');";

I modified it in :

 foreach ($keys as $key) {
            $column_name = (count($key->column_name) > 1) ? $key->column_name : reset($key->column_name);
            $keyArray[] = "\n\t\t\$this->forge->addForeignKey('$column_name','$key->foreign_table_name','$column_name','NO ACTION','CASCADE');";
        }
robinNcode commented 3 months ago

Thank you @AnwarQasem for your kind appreciation, also got your suggestion this will be fixed in the new release.

robinNcode commented 3 months ago

@AnwarQasem Your issue has been resolved on this release -> https://github.com/robinNcode/db_craft/releases/tag/v1.2