You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I create a table seeder for a table that uses metable, the meta columns don't get translated into key/value pairs on the related table. For example:
If I were to call (via artisan tinker): factory(App\Models\Business::class,10)->create(), I get this error:
Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'address' in 'field list' (SQL: insert into businesses (name, short_description, description, address, city, state, zip_code, facebook_url, youtube_url, google_plus_url, twitter_url, slug, updated_at, created_at) values (Donnelly Inc, Maxime et et sunt pariatur., Impedit autem voluptas necessitatibus blanditiis aut dolores. Est fugiat sunt quisquam. Cumque aut velit ut inventore., 9658 Hane Crest, Elmorestad, AR, 33942, http://www.wilderman.biz/ea-ullam-molestias-aut-quisquam-aspernatur, http://www.wuckert.org/, http://www.quitzon.net/, http://www.reilly.biz/assumenda-nam-iste-in-ea-laboriosam-dolorem-sapiente-fuga, donnelly-inc, 2017-01-26 16:59:25, 2017-01-26 16:59:25))'
What I have to do instead as a workaround, is setting the meta data into a separate factory definition:
<?php
use Illuminate\Database\Seeder;
class SuppliersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
factory(App\Supplier::class, 50)->create()->each(function ($supplier) {
$faker = Faker\Factory::create();
$company = $faker->company;
$supplier->setMeta([
'short_name' => $company,
'long_name' => $company.' '.$faker->companySuffix
]);
$supplier->save();
});
}
}
As you can see, saving of metadata can't be done in the same step as creating given Model, but instead we have to utilize setMeta function and update the Model we have created.
If I create a table seeder for a table that uses metable, the meta columns don't get translated into key/value pairs on the related table. For example:
In database/factories/ModelFactory.php:
If I were to call (via artisan tinker): factory(App\Models\Business::class,10)->create(), I get this error:
What I have to do instead as a workaround, is setting the meta data into a separate factory definition:
And then calling:
factory(App\Models\Business::class,10)->create()->each(function ($business) { $business->setMeta(factory(App\Models\BusinessMeta::class)->make()->toArray()); $business->save(); });
If there's a way to make a direct call to factory()->create() work without the each(), it would make things simpler.
The text was updated successfully, but these errors were encountered: