Question: I just started programming recently and I have doctrine fixture and foundry for my entities (`Advertisement`,`Category($id, $name)`, `User`).

Since I couldn't figure out how to get the my desired name out of foundry for a Category I tried to write it myself in fixture (completely ignoring `categoryFactory`) using below code.
But I'm getting only the last item of the array I've written (cpu).
(Only ads with cpu category, no other categories were saved in database)

Basically, what I had in my mind was to create Categories and make an `Advertisement` for each of them.

```php
class AppFixtures extends Fixture
{

    public function load(ObjectManager $manager): void
    {
        $category = new Category();
        $names = array(
             'pc',
            'laptop',
             'cpu');
        foreach ($names as $name)
        {
            $nam = $category->setName($name);
            $manager->persist($nam);

            UserFactory::createMany(3);
            AdvertisementFactory::createMany(20,[
                'user'=> UserFactory::random(),
                'category'=>$nam
            ]);
        }
        $manager->flush();
    }

}

```

Answer: 
Try this:

```
public function load(ObjectManager $manager): void
{ 
    $names = array(
         'pc',
         'laptop',
         'cpu'
    );

   foreach ($names as $name)
   {
       $category = new Category();
       $category->setName($name); 

       $manager->persist($category);        
   }

   $manager->flush();
}

```
I've finally solved it. @Anton M

```
    public function load(ObjectManager $manager): void
    {
    $names = array('pc', 'laptop', 'display','processor', 'cpu', 'gpu', 'ram', 'motherboard');

    foreach ($names as $name)
    {
        $category = new Category();
        $category->setName($name);
        $manager->persist($category);

        $advertisement = new Advertisement();
        UserFactory::createMany(10);
        AdvertisementFactory::createMany(20, function () use ($advertisement, $category) {
        return [
            'user' => UserFactory::random(),
            'category' => $category->addAdvertisement($advertisement)
        ];
        });

    }

    $manager->flush();

    }

```