0

My function findByDimensions() works correctly in Controller but if I use it in the DataFixture class, it always returns null.

Code in controller:

$manager = $this->getDoctrine()->getEntityManager();
$smRepository = $manager->getRepository('Something\Repository');
$smRepository->findByDimensions(1, 2);

I got the correct object here. But if I use it in DataFixture class, I always get null:

public function load(ObjectManager $manager) {
....
$smRepository = $manager->getRepository('Something\Repository');
$smRepository->findByDimensions(1, 2);
....
}

Where should be the mistake? The first manager is of the class EntityManager, the second is ObjectManager from DataFixture class.

2
  • Is the second code (DataFixture class) maybe executed in the Symfony test environment and using a different database? Commented Sep 13, 2014 at 11:16
  • That's not the issue, there is only one database. Commented Sep 13, 2014 at 15:14

1 Answer 1

3

When you're loading fixtures your database is empty.

This is cause by purging on doctrine:fixtures:load You can check this out:

doctrine:fixtures:load --append
Sign up to request clarification or add additional context in comments.

1 Comment

How do you work when an Entity has a relationship with another? Because you would need to put something on the Foreign Key. Do you need to create those other entities on the fly?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.