liip / liip/LiipFunctionalTestBundle
mongodb not hydrating references
- Dominant language
- PHP
- Stars
- 648
- Forks
- 179
- PR merge metrics
- No merged PRs in 30d
Description
I have a mongodb document with a referenced document:
/**
* Class User
*
* @MongoDB\Document
*/
class User
{
/**
* @MongoDB\Field(type="string")
*/
protected $email;
/**
* @var Contact
* @MongoDB\ReferenceOne(targetDocument="Document\Contact")
*/
private $contact;
/**
* {@inheritdoc}
*/
public function getEmail()
{
return $this->email;
}
/**
* @return Contact
*/
public function getContact(): Contact
{
return $this->contact;
}
/**
* @param Contact $contact
* @return User
*/
public function setContact(Contact $contact): User
{
$this->contact = $contact;
return $this;
}
}
When running a test:
public function testSample()
{
$fixtures = $this->loadFixtures([
'DataFixtures\UserFixtures',
], null, 'doctrine_mongodb');
$repository = $fixtures->getReferenceRepository();
/** @var User $user */
$user = $repository->getReference('guest-user');
$user->getEmail(); // Have to do this to hydrate
$user->getContact();
}
I have to call getEmail(), if I don't then getContact() returns null. It doesn't seem to be hydrating contact until I call another getter. As soon as I put getEmail() in before getContact() it returns a contact perfectly. Any idea on this? Thank you
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the loadFixtures, getReferenceRepository, and getReference path using the doctrine_mongodb fixture setup described in the report. Reproduce the difference between calling getContact() directly and calling getEmail() first, then trace the hydration behavior; done means the referenced Contact is available without the getter workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, php
- Domain
- databases, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100