Multi entity manager, wrong database selected
Hello, i'm using multiple entity managers in Symfony 2, but during a form
validation, the handleRequest method use the wrong one.
Here is my ORM configuration :
dbal:
default_connection: customer_database
connections:
customer_database:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
shared_database:
driver: %shared_database_driver%
host: %shared_database_host%
port: %shared_database_port%
dbname: %shared_database_name%
user: %shared_database_user%
password: %shared_database_password%
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: customer_em
entity_managers:
shared_em:
connection: shared_database
mappings:
KnFEngineBundle:
type: "annotation"
dir: "Entity/Shared"
customer_em:
connection: customer_database
mappings:
KnFEngineBundle:
type: "annotation"
dir: "Entity/Customer"
KnFModTextBundle: ~
KnFModMapBundle: ~
KnFModFormBundle: ~
And the function in my controller that validate the form :
public function addAction( $isLink )
{
$kernel = $this->container->get( 'knf_engine.kernel' );
$form = $this->createForm( new PageType( $isLink,
$kernel->getAvailablePageOwner() ) );
$request = $this->get( 'request' );
if( $request->getMethod() == 'POST' )
{
$page = new Page( $isLink );
$form->setData( $page );
$form->handleRequest( $request ); //the function call that throw
error
if( $form->isValid() )
{
$kernel->addPage( $page );
return $this->redirect( $this->generateUrl(
'knf_engine_admin_page' ) );
}
}
$args = array( 'form' => $form->createView(),
'url' => $this->getURL(),
'isLink' => $isLink );
if( $request->isXmlHttpRequest() )
{
return $this->render(
'KnFEngineBundle:admin:includes/pageadd_modal.html.twig', $args );
}
else
{
return $this->render( 'KnFEngineBundle:admin:pageadd.html.twig',
$args );
}
}
And the error :
An exception occurred while executing 'SELECT t0.id AS id1, t0.isLink AS
isLink2, t0.externalLink AS externalLink3, t0.isPopup AS isPopup4,
t0.address AS address5, t0.position AS position6, t0.title AS title7,
t0.active AS active8, t0.owner_id AS owner_id9 FROM Page t0 WHERE
t0.address = ?' with params ["dhfg"]:
SQLSTATE[42S02]: Base table or view not found: 1146 Table
'kreanet_framework_global.page' doesn't exist
But the entity is "Page" is defined in the Entity/Customer folder, that is
mapped to the customer entity manager (default em). As you can see,
doctrine try to access the data in the other entity manager.
After investigation, i understood that doctrine bind the form with the
database in the handleRequest() method (i used bind() before but is now
deprecated). I really don't know why doctrine is looking in that database.
Thanks for reading and sorry for my english, it's not my native language
but i hope you can understand my problem.
No comments:
Post a Comment