doctrine-orm
Doctrine Cascade Options for OneToMany
In the Doctrine2 documentation “9.6. Transitive persistence / Cascade Operations” there are few examples of how you should configure your entities so that when you persist $article, the $topic would be also persisted. In your case I’d suggest this annotation for Topic entity: /** * @OneToMany(targetEntity=”Article”, mappedBy=”topic”, cascade={“persist”, “remove”}) */ private $articles; The drawback of … Read more
Doctrine2 – No Metadata Classes to process
I think you took the config example from Doctrine2: getting started: $isDevMode = true; $config = Setup::createAnnotationMetadataConfiguration([__DIR__.”/src”], $isDevMode); The trick is now that the Setup::createAnnotationMetadataConfiguration method uses a SimpleAnnotationReader by default. You can change this behaviour by changing the fifth parameter to false: $isDevMode = true; $config = Setup::createAnnotationMetadataConfiguration([__DIR__.”/src”], $isDevMode, null, null, false); This will … Read more
The EntityManager is closed
My solution. Before doing anything check: if (!$this->entityManager->isOpen()) { $this->entityManager = $this->entityManager->create( $this->entityManager->getConnection(), $this->entityManager->getConfiguration() ); } All entities will be saved. But it is handy for particular class or some cases. If you have some services with injected entitymanager, it still be closed.
Getting a “true” object from a proxy object in doctrine2
This is unlikely to help in the specific instance for the question, since you’re relying on a third-party module, but you can prevent the lazy loading by setting the “fetch mode” for your entity to “EAGER”. User: ManyToOne: city: fetch: EAGER This can also be handled by annotations: @ManyToOne(targetEntity=”city”, fetch=”EAGER”) @JoinColumn(name=”city”, referencedColumnName=”id”) See http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#annref-manytoone None … Read more
Symfony2 QueryBuilder join ON and WITH difference
@florian gave you the correct answer but let me try to explain it on example: In sql, joins are done like this: SELECT * FROM category LEFT JOIN product ON product.category_id = category.id (or something like this) Now in Doctrine, you don’t need to use ON clause because doctrine knows that from relations annotations in … Read more