Discussion:
Symfony 2.3 Doctrine Translation Problem
r***@public.gmane.org
2013-07-11 19:49:53 UTC
Permalink
Hi,

I'm trying to implement translation through the *
StofDoctrineExtensionsBundle* I added this on the composer.json:

"stof/doctrine-extensions-bundle": "~***@dev",

On the *config.yml* I have

# 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
mappings:
StofDoctrineExtensionsBundle: ~

# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }

#Stof doctrine extension
stof_doctrine_extensions:
default_locale: en_US
orm:
default:
tree: false # not needed: listeners are not enabled by default
timestampable: true
sortable: true
sluggable: true
translatable: true

I created three entities to try this:

<?php

namespace RSantellan\SitioBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;

/**
* Category
*
* @ORM\Table(name="rs_category")
*
@ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
* @author Rodrigo Santellan
*/
class Category
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;


/**
* @Gedmo\SortablePosition
* @ORM\Column(type="integer")
*/
protected $orden;


/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(type="string", unique=true)
*/
private $slug;

/**
* var Projects
* @ORM\OneToMany(targetEntity="Project", mappedBy="category")
*/
private $projects;

public function setId($id)
{
$this->id = $id;
return $this;
}

/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}

/**
* Set name
*
* @param string $name
* @return Category
*/
public function setName($name)
{
$this->name = $name;

return $this;
}

/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}

public function __construct() {
$this->projects = new ArrayCollection();
}

public function __toString() {
return $this->getName();
}

/**
* Add projects
*
* @param \RSantellan\SitioBundle\Entity\Project $projects
* @return Category
*/
public function addProject(\RSantellan\SitioBundle\Entity\Project
$projects)
{
$this->projects[] = $projects;

return $this;
}

/**
* Remove projects
*
* @param \RSantellan\SitioBundle\Entity\Project $projects
*/
public function removeProject(\RSantellan\SitioBundle\Entity\Project
$projects)
{
$this->projects->removeElement($projects);
}

/**
* Get projects
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProjects()
{
return $this->projects;
}

/**
* Set orden
*
* @param integer $orden
* @return Category
*/
public function setOrden($orden)
{
$this->orden = $orden;

return $this;
}

/**
* Get orden
*
* @return integer
*/
public function getOrden()
{
return $this->orden;
}


/**
* Set slug
*
* @param string $slug
* @return Category
*/
public function setSlug($slug)
{
$this->slug = $slug;

return $this;
}

/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
}

<?php

namespace RSantellan\SitioBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;
use Symfony\Component\Validator\Constraints as Assert;

/**
* Project
*
*
@ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository")
* @ORM\Table(name="rs_project")
*
@Gedmo\TranslationEntity(class="RSantellan\SitioBundle\Entity\ProjectTranslation")
* @author Rodrigo Santellan
*/
class Project{
/**
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
*/
protected $id;

/**
* @Gedmo\Translatable
* @ORM\Column(type="string", length=100)
*/
protected $name;

/**
*
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $cliente;

/**
* @Gedmo\Translatable
* @ORM\Column(type="text", nullable=true)
*/
protected $tipo_de_trabajo;

/**
* @Gedmo\Translatable
* @ORM\Column(type="text", nullable=true)
*/
protected $description;


/**
* @Gedmo\SortablePosition
* @ORM\Column(type="integer")
*/
protected $orden;

/**
* @Gedmo\Locale
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
private $locale;



/**
*
* @ORM\ManyToOne(targetEntity="Category", inversedBy="projects")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
* @Assert\NotBlank()
*
*/
protected $category;

/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(type="string", unique=true)
*/
protected $slug;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}

/**
* Set name
*
* @param string $name
* @return Project
*/
public function setName($name)
{
$this->name = $name;

return $this;
}

/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* Set cliente
*
* @param string $cliente
* @return Project
*/
public function setCliente($cliente)
{
$this->cliente = $cliente;

return $this;
}

/**
* Get cliente
*
* @return string
*/
public function getCliente()
{
return $this->cliente;
}

/**
* Set tipo_de_trabajo
*
* @param string $tipoDeTrabajo
* @return Project
*/
public function setTipoDeTrabajo($tipoDeTrabajo)
{
$this->tipo_de_trabajo = $tipoDeTrabajo;

return $this;
}

/**
* Get tipo_de_trabajo
*
* @return string
*/
public function getTipoDeTrabajo()
{
return $this->tipo_de_trabajo;
}

/**
* Set description
*
* @param string $description
* @return Project
*/
public function setDescription($description)
{
$this->description = $description;

return $this;
}

/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}

/**
* Set orden
*
* @param integer $orden
* @return Project
*/
public function setOrden($orden)
{
$this->orden = $orden;

return $this;
}

/**
* Get orden
*
* @return integer
*/
public function getOrden()
{
return $this->orden;
}

/**
* Set category
*
* @param \RSantellan\SitioBundle\Entity\Category $category
* @return Project
*/
public function setCategory(\RSantellan\SitioBundle\Entity\Category
$category = null)
{
$this->category = $category;

return $this;
}

/**
* Get category
*
* @return \RSantellan\SitioBundle\Entity\Category
*/
public function getCategory()
{
return $this->category;
}

/**
* Set slug
*
* @param string $slug
* @return Project
*/
public function setSlug($slug)
{
$this->slug = $slug;

return $this;
}

/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}

public function getFullClassName()
{
return get_class($this);
}


public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}

Doing *php app/console generate:doctrine:entities* *RSantellanSitioBundle*generated this new class


<?php

namespace RSantellan\SitioBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation;


/**
* @ORM\Table(name="rs_project_translations", indexes={
* @ORM\Index(name="rs_project_translation_idx", columns={"locale",
"object_class", "field", "foreign_key"})
* })
*
@ORM\Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
* @author rodrigo
*/
class ProjectTranslation extends AbstractTranslation
{
//put your code here
/**
*
* @var integer
*
*/
protected $id;

/**
* @var string
*/
protected $locale;

/**
* @var string
*/
protected $objectClass;

/**
* @var string
*/
protected $field;

/**
* @var string
*/
protected $foreignKey;

/**
* @var string
*/
protected $content;


/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}

/**
* Set locale
*
* @param string $locale
* @return ProjectTranslation
*/
public function setLocale($locale)
{
$this->locale = $locale;

return $this;
}

/**
* Get locale
*
* @return string
*/
public function getLocale()
{
return $this->locale;
}

/**
* Set objectClass
*
* @param string $objectClass
* @return ProjectTranslation
*/
public function setObjectClass($objectClass)
{
$this->objectClass = $objectClass;

return $this;
}

/**
* Get objectClass
*
* @return string
*/
public function getObjectClass()
{
return $this->objectClass;
}

/**
* Set field
*
* @param string $field
* @return ProjectTranslation
*/
public function setField($field)
{
$this->field = $field;

return $this;
}

/**
* Get field
*
* @return string
*/
public function getField()
{
return $this->field;
}

/**
* Set foreignKey
*
* @param string $foreignKey
* @return ProjectTranslation
*/
public function setForeignKey($foreignKey)
{
$this->foreignKey = $foreignKey;

return $this;
}

/**
* Get foreignKey
*
* @return string
*/
public function getForeignKey()
{
return $this->foreignKey;
}

/**
* Set content
*
* @param string $content
* @return ProjectTranslation
*/
public function setContent($content)
{
$this->content = $content;

return $this;
}

/**
* Get content
*
* @return string
*/
public function getContent()
{
return $this->content;
}
}

Now I'm trying to generate the doctrine cruds *php app/console
generate:doctrine:crud --entity="RSantellanSitioBundle:Project"*

And what I get is:
[Doctrine\ORM\Mapping\MappingException]

No identifier/primary key specified for Entity
"RSantellan\SitioBundle\Entity\ProjectTranslation" sub class of
"Gedmo\Translatable\Entity\Mappe
dSuperclass\AbstractTranslation". Every Entity must have an
identifier/primary key.

I need to implement translations of the Entities on the database. I done a
lot of projects with multi language in Symfony 1.4 but trying to migrate
one too Symfony 2.3 is become a really hard work, because all the thing
that where given in Symfony 1.4 are gone...

Any idea, any help will be really appreciated.

Regards
--
--
If you want to report a vulnerability issue on Symfony, please read the procedure on http://symfony.com/security

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
---
You received this message because you are subscribed to the Google Groups "Symfony2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symfony2+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Mark Badolato
2013-07-11 20:19:51 UTC
Permalink
Post by r***@public.gmane.org
class ProjectTranslation extends AbstractTranslation
{
//put your code here
/**
*
*
*/
protected $id;
It's exactly as the error message specifies; There is no identifier/primary
key defined.

Needs to be

/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
--
--
If you want to report a vulnerability issue on Symfony, please read the procedure on http://symfony.com/security

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
---
You received this message because you are subscribed to the Google Groups "Symfony2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symfony2+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
r***@public.gmane.org
2013-07-11 20:51:05 UTC
Permalink
Ohhh... Thank you very much!! Putting that has fixed the problem.

But I don't understand why it doesn't take the parent annotations.

Now I'm facing the problem that it will not save the entity traslation:

[2/2] QueryException: [Semantical Error] line 0, col 9 near 'content,
t.field': Error: Class RSantellan\SitioBundle\Entity\ProjectTranslation has
no field or association named content

*vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php at line 49*

1. public static function semanticalError($message, $previous = null)
2. {
3. return new self('[Semantical Error] ' . $message, 0, $previous
);
4. }
5.


[1/2] QueryException: SELECT t.content, t.field FROM
RSantellan\SitioBundle\Entity\ProjectTranslation t WHERE t.foreignKey =
:objectId AND t.locale = :locale AND t.objectClass = :objectClass
*vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php at line 39*


1. public static function dqlError($dql)
2. {
3. return new self($dql);
4. }

The project entity was saved. What I'm missing?
Post by Mark Badolato
Post by r***@public.gmane.org
class ProjectTranslation extends AbstractTranslation
{
//put your code here
/**
*
*
*/
protected $id;
It's exactly as the error message specifies; There is no
identifier/primary key defined.
Needs to be
/**
*
*/
protected $id;
--
--
If you want to report a vulnerability issue on Symfony, please read the procedure on http://symfony.com/security

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
---
You received this message because you are subscribed to the Google Groups "Symfony2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symfony2+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Jasper N. Brouwer
2013-07-12 06:43:12 UTC
Permalink
Post by r***@public.gmane.org
class ProjectTranslation extends AbstractTranslation
{
// ...
}
You are redefining everything from AbstractTranslation in your own ProjectTranslation.

You should remove all content from ProjectTranslation so that you just have:

/**
* @ORM\Table(name="rs_project_translations", indexes={
* @ORM\Index(name="rs_project_translations_idx", columns={"locale", "object_class", "field", "foreign_key"})
* })
* @ORM\Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
*/
class ProjectTranslation extends AbstractTranslation
{
}

That's all you need :)
--
Jasper
Post by r***@public.gmane.org
Ohhh... Thank you very much!! Putting that has fixed the problem.
But I don't understand why it doesn't take the parent annotations.
[2/2] QueryException: [Semantical Error] line 0, col 9 near 'content, t.field': Error: Class RSantellan\SitioBundle\Entity\ProjectTranslation has no field or association named content
vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php at line 49
• public static function semanticalError($message, $previous = null)
• {
• return new self('[Semantical Error] ' . $message, 0, $previous);
• }

[1/2] QueryException: SELECT t.content, t.field FROM RSantellan\SitioBundle\Entity\ProjectTranslation t WHERE t.foreignKey = :objectId AND t.locale = :locale AND t.objectClass = :objectClass
vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php at line 39
• public static function dqlError($dql)
• {
• return new self($dql);
• }
The project entity was saved. What I'm missing?
--
--
If you want to report a vulnerability issue on Symfony, please read the procedure on http://symfony.com/security

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
---
You received this message because you are subscribed to the Google Groups "Symfony2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symfony2+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
r***@public.gmane.org
2013-07-12 13:10:36 UTC
Permalink
Now it really works!!

That content of that class was generated by *php app/console
generate:doctrine:entities RSantellanSitioBundle* so now I have to always
remember to delete all content.

Thank you very much!!!
Post by Jasper N. Brouwer
Post by r***@public.gmane.org
class ProjectTranslation extends AbstractTranslation
{
// ...
}
You are redefining everything from AbstractTranslation in your own ProjectTranslation.
/**
columns={"locale", "object_class", "field", "foreign_key"})
* })
*
@ORM\Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
*/
class ProjectTranslation extends AbstractTranslation
{
}
That's all you need :)
--
Jasper
Post by r***@public.gmane.org
Ohhh... Thank you very much!! Putting that has fixed the problem.
But I don't understand why it doesn't take the parent annotations.
[2/2] QueryException: [Semantical Error] line 0, col 9 near 'content,
t.field': Error: Class RSantellan\SitioBundle\Entity\ProjectTranslation has
no field or association named content
Post by r***@public.gmane.org
vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php at line 49
• public static function semanticalError($message, $previous
= null)
Post by r***@public.gmane.org
• {
• return new self('[Semantical Error] ' . $message, 0,
$previous);
Post by r***@public.gmane.org
• }
•
[1/2] QueryException: SELECT t.content, t.field FROM
RSantellan\SitioBundle\Entity\ProjectTranslation t WHERE t.foreignKey =
:objectId AND t.locale = :locale AND t.objectClass = :objectClass
Post by r***@public.gmane.org
vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php at line 39
• public static function dqlError($dql)
• {
• return new self($dql);
• }
The project entity was saved. What I'm missing?
--
--
If you want to report a vulnerability issue on Symfony, please read the procedure on http://symfony.com/security

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
---
You received this message because you are subscribed to the Google Groups "Symfony2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symfony2+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Loading...