Search code examples
phpmodulemigrationfixturesfuelphp

How to build Fixtures in fuelphp?


I am using FuelPHP 1.8 and I am searching a way to write fixtures for fill my databases in a initial stage.

I see this question about DB seeding in FuelPHP in FuelPHP, but I don't know if it applies too for fixtures.


Solution

  • The current Fuel version doesn't have any provisions for either seeding nor fixtures.

    It means you need to create a method of loading data (a task perhaps) from somewhere, and maniplate it so that you end up with a multi-dimensional assoc array where every array item represents a record. You can then loop over that array, construct a DB::insert() object for eash row, and execute that.

    Using the ORM isn't advised, as that caches objects by default, so it isn't suitable for loading large datasets. If you need to use the ORM, for example to create relations, you need to disable the object cache, by adding from_cache(false) before you call save().