tattersoftware / codeigniter4-schemas

Database schema management, for CodeIgniter 4
MIT License
22 stars 9 forks source link

Error When Running `php spark schemas` with CodeIgniter Shield: Cannot Instantiate Abstract Class #48

Open aslanutku opened 6 months ago

aslanutku commented 6 months ago

Hello,

I've encountered an issue when using the Tatter\Schemas package in combination with the official CodeIgniter Shield package. When attempting to run the php spark schemas command to generate schema files, I receive the following error message:

CodeIgniter v4.4.4 Command Line Tool - Server Time: 2024-02-05 22:02:35 UTC+00:00

[Error]
Cannot instantiate abstract class CodeIgniter\Shield\Models\BaseModel
at VENDORPATH/tatter/schemas/src/Drafter/Handlers/ModelHandler.php:173

Backtrace:
  1    VENDORPATH/tatter/schemas/src/Drafter/Handlers/ModelHandler.php:84
       Tatter\Schemas\Drafter\Handlers\ModelHandler()->getModels()

  2    VENDORPATH/tatter/schemas/src/Schemas.php:165
       Tatter\Schemas\Drafter\Handlers\ModelHandler()->draft()

  3    VENDORPATH/tatter/schemas/src/Commands/Schemas.php:57
       Tatter\Schemas\Schemas()->draft()

  4    SYSTEMPATH/CLI/Commands.php:65
       Tatter\Schemas\Commands\Schemas()->run()

  5    SYSTEMPATH/CLI/Console.php:46
       CodeIgniter\CLI\Commands()->run()

  6    ROOTPATH/spark:102
       CodeIgniter\CLI\Console()->run()

I believe this issue could be related to how the ModelHandler in the Tatter\Schemas package handles model instantiation, particularly with abstract classes like BaseModel in the Shield package.

Any guidance on resolving this error would be greatly appreciated.

Thank you.

mkuettel commented 5 months ago

A possible workaround might be relocating the abstract classes to a different namespace and adding this namespace to the config variable Schemas::$ignoredNamespaces

mkuettel commented 5 months ago

I stumbled upon the exact same thing, this is a quickfix https://github.com/tattersoftware/codeigniter4-schemas/pull/49