Closed Kwadz closed 7 years ago
This is because you are getting a non-initialized proxy (which will get initialized when you call anything else that getId()
on it, because each fixture is loaded separately and the EM is cleared between them (avoiding to do a flush on a huge unit of work the last time).
There is nothing wrong here.
How do you suggest to initialize the proxy?
class ProcessorDataLoader extends AbstractFixture implements OrderedFixtureInterface
{
public function load(ObjectManager $manager) {
$myProcessor = new Processor();
$myProcessor->setFactory("PaypalTransactionProcessor");
$myProcessor->setName("PaypalTransactionProcessor");
$manager->persist($myProcessor);
$manager->flush();
$this->addReference('my-processor', $myProcessor);
}
}
class TransactionDataLoader extends AbstractFixture implements OrderedFixtureInterface
{
private $maVar;
public function load(ObjectManager $manager) {
$transaction = new PaymentTransaction();
$processor = $this->getReference("my-processor");
$transaction->setProcessor($processor);
$transaction->setAmount(60);
$transaction->setCurrency("EUR");
$manager->persist($transaction);
$manager->flush();
}
}
@Kwadz You typically initialize a proxy by calling a getter on a not initialized property (not the id). But it doesn't matter in your case for your code to work you only need the id of your processor.
Close as invalid. Don't hesitate to reopen if you have clarification about an issue.
Do you suggest initializing the proxy by calling a getter like this:
class ProcessorDataLoader extends AbstractFixture implements OrderedFixtureInterface
{
public function load(ObjectManager $manager) {
$myProcessor = new Processor();
$myProcessor->setFactory("PaypalTransactionProcessor");
$myProcessor->setName("PaypalTransactionProcessor");
$myProcessor->getName(); // DO WE HAVE TO INITIALIZE LIKE THIS?
$manager->persist($myProcessor);
$manager->flush();
$this->addReference('my-processor', $myProcessor);
}
}
You don't need to initialize it. As soon as your code will need something from that processor it will initialize itself automatically, you don't need to do anything. The only reason why it's not initialized yet is because no part of your code needed it.
In all cases it should be at least usable by the other fixtures during the creation. And here it is not the case.
I made a new test. I realized the problem occurs during the second pass (many fixtures need the hotel-item-group
reference).
First pass:
Second pass:
So, I get:
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'item_group_id' cannot be null
To reproduce the error, I updated this repo which contains everything needed.
You just need to create the db and execute DefaultControllerTest::testLoadFixtures()
.
Could you reopen the issue until we fixed it?
Don't hesitate to reopen if you have clarification about an issue.
@mikeSimonson I can't repoen the issue as it's not me who closed it. Can you reopen it please ?
In fact a @ORM\JoinColumn
name was wrong. The issue came from the Offer
entity configuration.
When I reference an object which has attributes populated:
The attribute values disappear (except id) when I get the reference: