Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add after_creating to factory class #252

Closed
josephmancuso opened this issue Dec 4, 2020 · 0 comments · Fixed by #304
Closed

Add after_creating to factory class #252

josephmancuso opened this issue Dec 4, 2020 · 0 comments · Fixed by #304
Labels
feature request A feature that does not yet exist but will be a good addition to the library medium These issues are geared for people who have contributed to the project before

Comments

@josephmancuso
Copy link
Member

Here is an example in PHP:

$factory->afterCreating(Sku::class, function ($sku, $faker) {
    $skuUomId = factory(SkuUom::class)->create([
        "sku_id" => $sku->sku_id,
        "quantity" => 1,
        "gtin_prefix" => '00',
        "used_for_selling" => 1,
        "used_for_purchasing" => 1,
        "used_for_picking" => 1,
        "can_be_packaged" => 1,
    ])->sku_uom_id;

    $sku->base_uom_id = $skuUomId;
    $sku->default_sales_uom_id = $skuUomId;
    $sku->default_purchasing_uom_id = $skuUomId;
    $sku->default_picking_uom_id = $skuUomId;
    $sku->save();
});

After the factory is created, if there is an after_creating registered for that model it should pass the result and a faker instance to this callable

@josephmancuso josephmancuso added feature request A feature that does not yet exist but will be a good addition to the library medium These issues are geared for people who have contributed to the project before labels Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature that does not yet exist but will be a good addition to the library medium These issues are geared for people who have contributed to the project before
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant