relation between different connections in Symfony 2 - php

I'm new Symfony2 user and I need help!
I have two Bundles with entities:
// My\FooBundle\Entity\Foo.php
namespace My\FooBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(name="foo")
* #ORM\Entity
*/
class Foo
{
/*...*/
/**
* #ORM\OneToOne(targetEntity="My\BarBundle\Entity\Bar")
*/
private $bar;
}
And in another bundle:
// My\BarBundle\Entity\Bar.php
namespace My\BarBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(name="bar")
* #ORM\Entity
*/
class Bar
{
/*...*/
/**
* #ORM\Column(name="name", nullable=false)
*/
private $name;
}
And my config.yml:
doctrine:
dbal:
default_connection: foo
connections:
foo:
dbname: "foo"
bar:
dbname: "bar"
orm:
entity_managers:
foo:
connection: foo
mappings:
MyFooBundle: ~
MyBarBundle: ~
bar:
connection: bar
mappings:
MyBarBundle: ~
And SF creates Bar in Foo database.
Q: How do I create a relation between two connections in this situation?

Remove MyBarBundle bundle from foo connection.

Add database name to bar entity
// My\BarBundle\Entity\Bar.php
namespace My\BarBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(name="bar.bar")
* #ORM\Entity
*/
class Bar
{
/*...*/
/**
* #ORM\Column(name="name", nullable=false)
*/
private $name;
}
And following strings to config.yml:
doctrine:
dbal:
default_connection: foo
connections:
foo:
dbname: "foo"
bar:
dbname: "bar"
orm:
entity_managers:
foo:
connection: foo
mappings:
MyFooBundle: ~
MyBarBundle:
type: "annotation"
dir: ..\..\My\BarBundle\Entity
bar:
connection: bar
mappings:
MyBarBundle:
type: "annotation"
dir: ..\..\My\BarBundle\Entity

Related

doctrine:schema:update error There is no column with name '$column' on table '$table'

I've made some changes to my doctrine Entities and need to update the database and got the following error.
$ php bin/console doctrine:schema:update -vvv
[Doctrine\DBAL\Schema\SchemaException (30)]
There is no column with name 'fleet_no' on table 'fuelData'.
Exception trace:
() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaException.php:86
Doctrine\DBAL\Schema\SchemaException::columnDoesNotExist() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Table.php:671
Doctrine\DBAL\Schema\Table->getColumn() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php:711
Doctrine\DBAL\Platforms\MySqlPlatform->getPreAlterTableAlterPrimaryKeySQL() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php:639
Doctrine\DBAL\Platforms\MySqlPlatform->getPreAlterTableIndexForeignKeySQL() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php:621
Doctrine\DBAL\Platforms\MySqlPlatform->getAlterTableSQL() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaDiff.php:199
Doctrine\DBAL\Schema\SchemaDiff->_toSql() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaDiff.php:126
Doctrine\DBAL\Schema\SchemaDiff->toSaveSql() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/SchemaTool.php:883
Doctrine\ORM\Tools\SchemaTool->getUpdateSchemaSql() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php:115
Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand->executeSchemaCommand() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php:65
Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand->execute() at /home/sarah/workspace/telematics_tracker/vendor/doctrine/doctrine-bundle/Command/Proxy/UpdateSchemaDoctrineCommand.php:50
Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand->execute() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:261
Symfony\Component\Console\Command\Command->run() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:839
Symfony\Component\Console\Application->doRunCommand() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:185
Symfony\Component\Console\Application->doRun() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:80
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/sarah/workspace/telematics_tracker/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:116
Symfony\Component\Console\Application->run() at /home/sarah/workspace/telematics_tracker/bin/console:27
Which is correct as such, since I have a column called 'fleetNo' but not one called 'fleet_no' in the 'fuelData' table. This was not one of the changes that I made either.
I have searched the project directory for any other instance of 'fleet_no' but there aren't any.
Below is a copy of the fuelData entity.
<?php
// src/AppBundle/Entity/FuelData.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Column;
/**
* #ORM\Entity
* #ORM\Table(name="fuelData")
*
*
*/
class FuelData
{
/**
* #Assert\NotBlank()
* #ORM\Column(type="string")
* #ORM\Id
*/
public $fleetNo;
/**
* #Assert\NotBlank()
* #ORM\Column(type="string")
*/
public $startDate;
/**
* #Assert\NotBlank()
* #ORM\Column(type="string")
*/
public $endDate;
/**
* Set fleetNo
*
* #param string $fleetNo
*
* #return FuelData
*/
public function setFleetNo($fleetNo)
{
$this->fleetNo = $fleetNo;
return $this;
}
/**
* Get fleetNo
*
* #return string
*/
public function getFleetNo()
{
return $this->fleetNo;
}
/**
* Set startDate
*
* #param string $startDate
*
* #return FuelData
*/
public function setStartDate($startDate)
{
$this->startDate = $startDate;
return $this;
}
/**
* Get startDate
*
* #return string
*/
public function getStartDate()
{
return $this->startDate;
}
/**
* Set endDate
*
* #param string $endDate
*
* #return FuelData
*/
public function setEndDate($endDate)
{
$this->endDate = $endDate;
return $this;
}
/**
* Get endDate
*
* #return string
*/
public function getEndDate()
{
return $this->endDate;
}
}
The only thing that I can think of is that the column name is being converted from camelCase to underscore by something.
Is there something that I have missed or should I be looking in a different place?
Below are the relevant parts of my config.yml:
doctrine:
dbal:
default_connection: maxdb
connections:
maxdb:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
foxdb:
driver: pdo_mysql
host: "%database_host2%"
port: "%database_port2%"
dbname: "%database_name2%"
user: "%database_user2%"
password: "%database_password2%"
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: maxem
entity_managers:
maxem:
naming_strategy: doctrine.orm.naming_strategy.underscore
connection: maxdb
mappings:
AppBundle: ~
BWTCalendarBundle: ~
BWTFMBundle: ~
BWTHealthCheckBundle: ~
BWTSkytrackBundle: ~
BWTTelematicsBundle: ~
foxem:
naming_strategy: doctrine.orm.naming_strategy.underscore
connection: foxdb
mappings:
FoxBundle: ~
orm:
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: maxem
entity_managers:
maxem:
naming_strategy: doctrine.orm.naming_strategy.underscore
As you can see in your config you are using the UNDERSCORE naming strategy for the orm so that is what converts your field name.
You should do
app/console doctrine:schema:drop
to start off from clean then try changing the naming strategy.
In the end if you want to be sure to have the exact column name you want just add the name parameter to the colum annotation like so:
/**
* #Assert\NotBlank()
* #ORM\Column(type="string" name="fleetNo")
* #ORM\Id
*/
public $fleetNo;

Symfony2 : doctrine2 - "targetEntity" from another bundle with MultiDatabase

Entity 1
<?php
namespace Operat\SystemBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Operat\AgentsBundle\Entity\Agents;
/**
* Liensao
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Operat\SystemBundle\Entity\LiensaoRepository")
*/
class Liensao
{
// Liensao - Agents
/**
* #ORM\ManyToOne(targetEntity="Operat\AgentsBundle\Entity\Agents", inversedBy="liensao")
* #ORM\JoinColumn(name="colAgent_Code", referencedColumnName="CODE")
*/
protected $agent;
/*....*/
Entity 2
<?php
namespace Operat\AgentsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Operat\SystemBundle\Entity\Liensao;
/**
* Agents
*
* #ORM\Table(name="agents", indexes={#ORM\Index(name="Valide", columns={"Valide"}), #ORM\Index(name="GL", columns={"GL"}), #ORM\Index(name="NSOC", columns={"NSOC"})})
* #ORM\Entity
*/
class Agents
{
// Agents - Liensao
/**
* #ORM\OneToMany(targetEntity="\Operat\SystemBundle\Entity\Liensao", mappedBy="agent")
*/
protected $liensao;
Yet running
php app/console doctrine:schema:update --em=entities_system --dump-sql --force
gives the following error:
[Doctrine\Common\Persistence\Mapping\MappingException]
The class 'Operat\AgentsBundle\Entity\Agents' was not found in the chain configured namespaces Operat\SystemBundle\Entity, Operat\AdministrationBundle\Entity, FOS\UserBundle\Entity
Config.yml
orm:
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: entities_system
entity_managers:
entities_system:
connection: operat_system
mappings:
OperatSystemBundle: ~
FOSUserBundle: ~
entities_agents:
connection: operat_agents
mappings:
OperatAgentsBundle: ~

Sonata Missing argument

I have this Error when i'm trying to access my site with a fresh installation of sonata adminBUndle. I can see the list i can see the dashboard but if i try to add a post I got this message.
Missing argument 1 for Sonata\AdminBundle\Admin\Admin::__construct(),
called in
C:\wamp\www\sonata\vendor\sonata-project\doctrine-orm-admin-bundle\Sonata\DoctrineORMAdminBundle\Model\ModelManager.php on line 416 and defined in
C:\wamp\www\sonata\app\cache\dev\classes.php line 8120
anybody can help????
Ok thx for you're answer there is the code
Symfony 2.4.1
the entity
<?php
namespace Tic\ClasseBundle\Entity;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Doctrine\ORM\Mapping as ORM;
/**
* Groupe
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Tic\ClasseBundle\Entity\GroupeRepository")
*/
class Groupe extends Admin
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="groupe", type="string", length=255)
*/
private $groupe;
/**
* #var string
*
* #ORM\Column(name="enseignant", type="string", length=255)
*/
private $enseignant;
/**
* #var string
*
* #ORM\Column(name="grepere", type="string", length=255)
*/
private $grepere;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set groupe
*
* #param string $groupe
* #return Groupe
*/
public function setGroupe($groupe)
{
$this->groupe = $groupe;
return $this;
}
/**
* Get groupe
*
* #return string
*/
public function getGroupe()
{
return $this->groupe;
}
/**
* Set enseignant
*
* #param string $enseignant
* #return Groupe
*/
public function setEnseignant($enseignant)
{
$this->enseignant = $enseignant;
return $this;
}
/**
* Get enseignant
*
* #return string
*/
public function getEnseignant()
{
return $this->enseignant;
}
/**
* Set grepere
*
* #param string $grepere
* #return Groupe
*/
public function setGrepere($grepere)
{
$this->grepere = $grepere;
return $this;
}
/**
* Get grepere
*
* #return string
*/
public function getGrepere()
{
return $this->grepere;
}
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('enseignant', 'text',array('label'=>'Enseignants(es)'))
->add('groupe', 'text',array('label'=>'Groupe'))
->add('grepere', 'text',array('label'=>'Groupe Repere')) //if no type is specified, SonataAdminBundle tries to guess it
;
}
// Fields to be shown on filter forms
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('enseignant')
->add('grepere')
;
}
// Fields to be shown on lists
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('enseignant')
->add('grepere')
->add('groupe')
;
}
}
the config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: #TicClasseBundle/Resources/config/admin.yml }
framework:
#esi: ~
translator: { fallback: "%locale%" }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
sonata_admin:
title: Gestion de classe
sonata_block:
default_contexts: [cms]
blocks:
# Enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
# Your other blocks
sonata_doctrine_orm_admin:
# default value is null, so doctrine uses the value defined in the configuration
entity_manager: ~
templates:
form:
- SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig
filter:
- SonataDoctrineORMAdminBundle:Form:filter_admin_fields.html.twig
types:
list:
array: SonataAdminBundle:CRUD:list_array.html.twig
boolean: SonataAdminBundle:CRUD:list_boolean.html.twig
date: SonataAdminBundle:CRUD:list_date.html.twig
time: SonataAdminBundle:CRUD:list_time.html.twig
datetime: SonataAdminBundle:CRUD:list_datetime.html.twig
text: SonataAdminBundle:CRUD:base_list_field.html.twig
trans: SonataAdminBundle:CRUD:list_trans.html.twig
string: SonataAdminBundle:CRUD:base_list_field.html.twig
smallint: SonataAdminBundle:CRUD:base_list_field.html.twig
bigint: SonataAdminBundle:CRUD:base_list_field.html.twig
integer: SonataAdminBundle:CRUD:base_list_field.html.twig
decimal: SonataAdminBundle:CRUD:base_list_field.html.twig
identifier: SonataAdminBundle:CRUD:base_list_field.html.twig
currency: SonataAdminBundle:CRUD:list_currency.html.twig
percent: SonataAdminBundle:CRUD:list_percent.html.twig
choice: SonataAdminBundle:CRUD:list_choice.html.twig
url: SonataAdminBundle:CRUD:list_url.html.twig
show:
array: SonataAdminBundle:CRUD:show_array.html.twig
boolean: SonataAdminBundle:CRUD:show_boolean.html.twig
date: SonataAdminBundle:CRUD:show_date.html.twig
time: SonataAdminBundle:CRUD:show_time.html.twig
datetime: SonataAdminBundle:CRUD:show_datetime.html.twig
text: SonataAdminBundle:CRUD:base_show_field.html.twig
trans: SonataAdminBundle:CRUD:show_trans.html.twig
string: SonataAdminBundle:CRUD:base_show_field.html.twig
smallint: SonataAdminBundle:CRUD:base_show_field.html.twig
bigint: SonataAdminBundle:CRUD:base_show_field.html.twig
integer: SonataAdminBundle:CRUD:base_show_field.html.twig
decimal: SonataAdminBundle:CRUD:base_show_field.html.twig
currency: SonataAdminBundle:CRUD:base_currency.html.twig
percent: SonataAdminBundle:CRUD:base_percent.html.twig
choice: SonataAdminBundle:CRUD:show_choice.html.twig
url: SonataAdminBundle:CRUD:show_url.html.twig
and the admin.yml
services:
sonata.admin.post:
class: Tic\ClasseBundle\Entity\Groupe
tags:
- { name: sonata.admin, manager_type: orm, group: "Gestion de classe", label: "Groupe" }
arguments:
- ~
- Tic\ClasseBundle\Entity\Groupe
- ~
calls:
- [ setTranslationDomain, [AcmeDemoBundle]]
thax
Your entity class Groupe is incorrect.
It will not extend Sonata admin class.
Methods configureListFields, configureFormFields, configureDatagridFilters should not be here. They must be in separate admin class(an analog symfony controller class)
Example:
<?php
namespace Tic\ClasseBundle\Controller\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
class GroupeAdmin extends Admin
{
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->addIdentifier('name')
->add('country');
}
protected function configureFormFields(FormMapper $form)
{
$form
->add('id', null, [
'attr' => [
'readonly' => true,
],
])
->add('name')
->add('country');
}
protected function configureDatagridFilters(DatagridMapper $filter)
{
$filter
->add('id')
->add('name')
->add('country');
}
}
The entity and admin page should be separated from each other. Your entity shouldn't extend the Admin class Sonata provides, but you should create a new file instead which extend the Admin class.
sonata.admin.post:
class: Tic\ClasseBundle\Admin\AdminGroupe /*Locating the admin file*/
tags:
- { name: sonata.admin, manager_type: orm, group: "Gestion de classe", label: "Groupe" }
arguments:
- ~
- Tic\ClasseBundle\Entity\Groupe
- ~
calls:
- [ setTranslationDomain, [AcmeDemoBundle]]
I highly suggest to read the documentation (again) Sonata provides see: https://sonata-project.org/bundles/admin/3-x/doc/getting_started/creating_an_admin.html

Mapping exception using Stof/Gedmo Translation

I'm migrating my Symfony 2.0 project to version 2.1rc1. After installing the stof/doctrine-extensions-bundle and the gedmo/doctrine-extensions and test my application I get the following error:
No identifier/primary key specified for Entity "Company\TestBundle\Entity\PageTranslation" sub class of "Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation". Every Entity must have an identifier/primary key.
My config.yml looks like this:
# Doctrine Configuration
doctrine:
dbal:
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%
connection: default
auto_mapping: true
mappings:
gedmo_translatable:
type: annotation
prefix: Gedmo\Translatable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
alias: GedmoTranslatable # this one is optional and will default to the name set for the mapping
is_bundle: false
gedmo_translator:
type: annotation
prefix: Gedmo\Translator\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Entity"
alias: GedmoTranslator # this one is optional and will default to the name set for the mapping
is_bundle: false
stof_doctrine_extensions:
default_locale: en
translation_fallback: true
orm:
default:
translatable: true
sluggable: true
According to the documentation of StofDoctrineExtensionsBundle this should be fine. The only thing I'm not sure of is the auto_mapping: true option.
The only code I've changed in my project is in my CategoryTranslation class. I've replaced:
use Stof\DoctrineExtensionsBundle\Entity\AbstractTranslation;
by:
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation;
Because the Stof-bundle doesn't have an AbstractTranslation class anymore.
Can someone tell me how I can fix this?
My PageTranslation entity before:
class PageTranslation extends AbstractTranslation
{
/**
* All required columns are mapped through inherited superclass
*/
}
My PageTranslation entity after generating the entities on the commandline:
class PageTranslation extends AbstractTranslation
{
/**
* All required columns are mapped through inherited superclass
*/
/**
* #var integer $id
*/
private $id;
/**
* #var string $locale
*/
private $locale;
.....etc....
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set locale
*
* #param string $locale
* #return PageTranslation
*/
public function setLocale($locale)
{
$this->locale = $locale;
return $this;
}
/**
* Get locale
*
* #return string
*/
public function getLocale()
{
return $this->locale;
}
..etc....
}
If you are using StofDoctrineExtensions you don't need gedmo/doctrine-extensions. Also isn't necessary to generate anything in PageTranslation

Symfony 2: Doctrine can't create relationship

I'm very new to Symfony 2.0 and doctrine. I have state and customer entity in different bundle. I just want to add relation between state and customer. I'm coded state and customer entities. Here is the my code:
/**
* #orm:Entity
*/
class Customer
{
/**
* #orm:Id
* #orm:Column(type="integer")
* #orm:GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #OneToOne(targetEntity="State")
* #JoinColumn(name="state_id", referencedColumnName="id")
*/
protected $state;
}
/**
* #orm:Entity
*/
class State
{
/**
* #orm:Id
* #orm:Column(type="integer")
* #orm:GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #orm:Column(type="string", length="50")
*/
protected $name;
}
And my config file:
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
dbname: %database_name%
user: %database_user%
password: %database_password%
orm:
auto_generate_proxy_classes: %kernel.debug%
mappings:
FogCustomerBundle: { type: annotation, dir: Entity/ }
FogMainBundle: { type: annotation, dir: Entity/ }
So my problem is when I generate schema using php app/console doctrine:schema:create command tables are generated. But relationship doesn't generated /state column doesn't generead in customer table/. Why? I don't have any idea? I'll very happy for every advise and post.
You can run into that problem if you're closely following examples from the Doctrine2 documentation, because Symfony2 places all the Doctrine2 annotations into the orm namespace, which you seem to be missing on your OneToOne and JoinColumn annotations. Your code for the $state property should look like this:
/**
* #orm:OneToOne(targetEntity="State")
* #orm:JoinColumn(name="state_id", referencedColumnName="id")
*/
protected $state;
EDIT: With changes introduced in Symfony2 beta2, annotations have changed a little. Annotations need to be imported before they are used; importing Doctrine looks like this:
use Doctrine\ORM\Mapping as ORM;
Then the new usage looks like this:
/**
* #ORM\OneToOne(targetEntity="State")
* #ORM\JoinColumn(name="state_id", referencedColumnName="id")
*/
protected $state;
There is some discussion of further changes to the annotation system; if these changes are rolled out, I'll be back with another edit.

Categories