Skip to content

Improve FakerController to work with relations #17

Closed
SOHELAHMED7/yii2-app-api
#3
@cebe

Description

@cebe

Faker Controller should be able to detect relations and set the foreign key values accordingly.

Inside this for loop:

https://github.com/cebe/yii2-app-api/blob/f3facab5d0978a30f77535913a442547a4ab42e7/console/commands/FakerController.php#L26-L32

Check for model relations (yii2-openapi could add a list of known relations to the Faker class for this) and add relations to existing models selecting the existing foreign keys.

e.g.

$model->user_id = $faker->randomElement(User::find()->select('id')->column());

The perfect implementation would event sort models by relation dependencies before generating fake data.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions