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
Related
I'm building my first Symfony bundle. I want to use Models instead of Entity so I have a directory Model which contains only one model. Also I have a mapping for this model which is located in Resources/config/doctrine/mymodel.orm.yaml. When I run /bin/console doctrine:migration:diff it says No changes detected in your mapping information
Here's is my model
class MyModel
{
/**
* #var mixed
*/
private $id;
/**
* #var string
*/
private $user;
/**
* #return mixed
*/
public function getId()
{
return $this->id;
}
/**
* #return null|string
*/
public function getUser(): ?string
{
return $this->user;
}
/**
* #param string $user
*
*/
public function setUser(string $user): self
{
$this->user = $user;
return $this;
}
and the mymodel.orm.yaml
MyNamespace\MyBundle\Model\MyModel:
type: mappedSuperclass
repositoryClass: MyNamespace\MyBundle\Repository\MyModelRepository
id:
id:
type: integer
generator:
strategy: AUTO
fields:
user:
type: string
What I'm missing here?
UPDATE
I'm using symfony 4.2.3
Here's my doctrine.yaml
parameters:
env(DATABASE_URL): ''
doctrine:
dbal:
driver:
charset: utf8
default_table_options:
charset: utf8
collate: utf8_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
entity_managers:
default:
auto_mapping: true
mappings:
MyBundle: ~
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;
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
I have a problem trying to get data from a table (via entity) using Doctrine2 in a Symfony2.1 project. Here is the controller where I get the error:
/**
* Country list
*/
public function countrylistAction()
{
$em = $this->getDoctrine()->getManager();
$countryList = $em->getRepository('ProjectBaseBundle:SYS_TCountry')
->findAll();
$serializer = new Serializer(array(new GetSetMethodNormalizer()),
array('json' => new JsonEncoder()));
return new Response($serializer->serialize($countryList, 'json'));
}
The entity:
<?php
namespace Company\Project\BaseBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* #ORM\Entity
* #ORM\Table(name="SYS_TCountry")
*/
class SYS_TCountry
{
/**
* #ORM\Id
* #ORM\Column(type="string", length=3, nullable=false)
* #var string
*/
protected $idcountry;
/**
* #ORM\Column(type="string", length=75, nullable=false)
* #Assert\NotBlank()
* #var string
*/
protected $name;
....
public function getIdcountry() { return $this->idcountry; }
public function getName() { return $this->name; }
public function getA2() { return $this->a2; }
public function getA3() { return $this->a3; }
public function getIdstatus() { return $this->idstatus; }
public function setIdcountry($idcountry) { $this->idcountry = $idcountry; }
public function setName($name) { $this->name = $name; }
public function setA2($a2) { $this->a2 = $a2; }
public function setA3($a3) { $this->a3 = $a3; }
public function setIdstatus($idstatus) { $this->idstatus = $idstatus; }
public function __toString() { return $this->idcountry; }
}
Config.yml:
# 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%
auto_mapping: true
And this is the error:
Warning: class_parents():
Class Company\Project\BaseBundle\Entity\SYS_TCountry does not exist and could not be loaded in
/var/www/project/src/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php line 40
It is strange because, as Doctrine says in console, the mapping is properly done: I test it executing php app/console doctrine:mapping:info:
[OK] Company\Project\BaseBundle\Entity\SYS_TCountry
and if I execute a query in console everything goes fine -> app/console doctrine:query:sql 'SELECT * FROM SYS_TCountry', that return results.
I do not know if using Symfony2.1 I have to configure something different to the 2.0 version, but seems the same because the mapping is Doctrine responsibility.
Symfony follows the PSR-0 standard for filenames. That, amongst other things, means that if you use an underscore in your class name, it will replace it with a directory separator when deciding where your class should live, like this:
\namespace\package\Class_Name => /path/to/project/lib/vendor/namespace/package/Class/Name.php
So, if you have a class named SYS_TCountry it would expect to find it in
Company/Project/BaseBundle/Entity/SYS/TCountry.php
instead of
Company/Project/BaseBundle/Entity/SYS_TCountry.php
I think that your best solution would be to change the filename and class name to SYSTCountry. You donĀ“t need to change the table name.
Your class entity name is not compliant with PSR-0 which causes the loading error.
If you rename your entity to SYSTCountry everything will work fine!
Edit: Default Symfony2 and Doctrine autoloaders ARE PSR-0 compliant.
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.