B
B
BonBon Slick2018-05-16 19:29:00
symfony
BonBon Slick, 2018-05-16 19:29:00

How to properly load fixtures with dependencies?

public function load(ObjectManager $manager) : void
    {
        $category =  new InvoiceCategory('BonBonSlickCat');
        $vendor =  new User('BonBonSlick');
        $manager->persist(new Invoice(10, $category, $vendor));
        $manager->flush();
    }

    /**
     * {@inheritdoc}
     */
    public function getDependencies() : array
    {
        return [
            InvoiceCategoryFixtures::class,
        ];
    }

It will give an error, since we do not persist the data on which the invoice depends, but if we persist, it will give an error that such data already exists, because we load them depending. So how do you properly load fixtures with dependencies?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
voronkovich, 2018-05-16
@BonBonSlick

https://symfony.com/doc/master/bundles/DoctrineFix...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question