Search code examples
symfonydoctrine-ormsylius

Amazon Aurora db with Doctrine


I need some help, I was working with mysql and doctrine and all was perfect, but now I'm using Auroradb which uses two instances (reader and writer). At first I tried to use two entity managers, one for writing and other for reading, but I got a problem with SyliusRbacBundle.

so, is there another way to use aurora and doctrine?????

UPDATE 1

this is the error that I get after using Daniel's config

A new entity was found through the relationship 'Litigon\UserBundle\Entity\User#authorizationRoles' that was not configured to cascade persist operations for entity: SuperAdministrador. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}).

so, if I merge the default entity manager as a lot of people suggest, I get problems with aurora 'cause of the other manager is for the reader instance and then when flushing aurora says that isn't allowed to write.


Solution

  • You need to specify where the models or entities actually live in doctrine config, also is important to notice that Sylius models are usually located on the component and not in the bundle. Finally, but not least important, can only have one connection with auto mapping:

    orm:
            auto_generate_proxy_classes: "%kernel.debug%"
            default_entity_manager: default
            entity_managers:
                default:
                    connection: default
                    mappings:
                        loggable:
                            type: annotation
                            alias: Gedmo
                            prefix: Gedmo\Loggable\Entity
                            dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
                        FOSUserBundle:
                            type: xml
                            dir: Resources/config/doctrine-mapping
                            prefix: FOS\UserBundle\Model
                        SyliusRbacBundle:
                          type: xml
                          dir: Resources/config/doctrine/model
                          prefix: Sylius\Component\Rbac\Model
                        SyliusResourceBundle: ~
                        OtherBundle: ~
                writer:
                    connection: writer
                    mappings:
                        loggable:
                            type: annotation
                            alias: Gedmo
                            prefix: Gedmo\Loggable\Entity
                            dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
                        FOSUserBundle:
                          type: xml
                          dir: Resources/config/doctrine-mapping
                          prefix: FOS\UserBundle\Model
                        SyliusRbacBundle:
                            type: xml
                            dir: Resources/config/doctrine/model
                            prefix: Sylius\Component\Rbac\Model
                        SyliusResourceBundle: ~