Skip to content

Conversation

phroggyy
Copy link

This resolves #97. Currently, the command for using existing data rather than new data is model:factoryName, as compared to the default factory:factoryName. If there is no existing data, an entry will be created in the same fashion as factory:factoryName.

This means that, given the following conditions (and assuming we have our relations correctly defined):

$factory('App\User', [
    'first_name'     => $faker->firstName,
    'last_name'     => $faker->lastName,
    'email'             => $faker->unique()->email,
    'password'      => bcrypt($faker->word),
]);

$factory('App\Post', 'post_with_existing_user', [
    'user_id'       => 'model:App\User',
    'title'                => $faker->sentence,
    'body'              => $faker->lastName,
]);

then

Factory::create('post_with_existing_user');
Will produce a result identical to

Factory::create('App\User');
Factory::create('post_with_existing_user');

phroggyy added 21 commits May 23, 2015 19:04
… model:FactoryName instead of factory:FactoryName for the foreign key
…g entry. The related model is currently not eager-loaded, I think, so I expect errors in further testing...
…eady been assigned (since a `factory:factoryName` attribute will create a new entry of `factoryName`, which might otherwise be taken by `model:factoryName`)
…Name` attribute without having existing data
…ntity for two relationships on one parent entity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to specify relation create new or use existing
1 participant