Answer the question
In order to leave comments, you need to log in
How to properly implement entity communication in Symfony2 using Doctrine and probably different entity managers?
Entity association scheme:
Product many-to-one Category
Product one-to-many Tag
It is necessary that the following scheme work:
Doctrine EntityManager is used for Product and Category,
and own ObjectManager is used for Tag
I would like to hear implementation methods.
PS
A separate ObjectManager is needed in order to get data not directly from the database, but from another source, such as Memcache or a file
Answer the question
In order to leave comments, you need to log in
You can load tags via postLoad ( docs.doctrine-project.org/en/2.0.x/reference/event...
if you are going to do joins from different databases, then Doctrine allows you to do this: Cross Database Joins
does not explicitly say everywhere that join will not work with several EntityManagers, only with one, which will turn out when auto_mapping works: true
for this you write in config.yml settings:
doctrine:
dbal:
default_connection: main_db
connections:
main_db:
driver: "%database_users_driver%"
host: "%database_users_host%"
port: "%database_users_port%"
dbname: "%database_users_name%"
user: "%database_users_user%"
password: "%database_users_password%"
charset: UTF8
other_db:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
/**
* Product
*
* @ORM\Table(name="main_db.Product")
* @ORM\Entity(repositoryClass="AcmeBundle\Entity\ProductRepository")
*
*/
class Product
{ ....
$sql = "SELECT p FROM AcmeBundle:Product p JOIN p.tag t WHERE ... ORDER BY ...";
query = $this->_em->createQuery($sql)->setParameters(array(...));
return $query->getResult();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question