I'm working in my first distributable bundle and I have some questions about how to reuse the "exists user entity" in my bundle. The aim of my bundle is to relate the ticket entity with the user entity.
I'm trying to relate entities between different bundles when the 'referencedColumnName' of the TargetEntity is different to 'id'.
I'm following the Resolve Target Entity Docs and works fine to me Only when the primary key of the "targetEntity" is named exactly as "id".
Example:
// file: vendor\Kdrmklabs\Bundle\TicketBundle\Entity\Ticket.php
class Ticket {
/**
* @ORM\ManyToOne(targetEntity="\Kdrmklabs\Bundle\TicketBundle\Model\UserInterface")
*/
private $user;
}
// file: vendor\Kdrmklabs\Bundle\TicketBundle\Model\UserInterface.php;
interface UserInterface {
public function getId();
}
# file: app/config/config.yml
doctrine:
orm:
auto_mapping: true
resolve_target_entities:
Kdrmklabs\Bundle\TicketBundle\Model\UserInterface: AppBundle\Entity\User
If the primary key of the entity AppBundle/Entity/User
names "id", the relationship between my bundle and this entity works fine.
// file: src/AppBundle/Entity/User.php
class User implements \Kdrmklabs\Bundle\TicketBundle\Model\UserInterface
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
}
but otherwise, an exception occurs:
// file: src/AppBundle/Entity/User.php
class User implements \Kdrmklabs\Bundle\TicketBundle\Model\UserInterface
{
/**
* @var integer
*
* @ORM\Column(name="id_customer", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
}
Column name 'id' referenced for relation from \Kdrmklabs\Bundle\TicketBundle\Entity\Ticket towards AppBundle\Entity\User does not exists.
I know if you specify the value of the foreign key in the annotation @ORM\JoinColumn(referencedColumnName="id_of_the_external_user_entity")
this will works great, But from my bundle I have no way of knowing the name of the foreign key with my actual configuration.
Is there any way to create a relationship between two entities regardless of the name of these primary keys ?
May be I can request to the user specify in the app/config/config.yml the name of the primary key of him "user entity" and somehow specify this value to doctrine to create the right relationship between the entities of my bundle and entities of the user that installed my bundle. But, How can I do it?
Thank you. regards
Thanks a lot in advance!!
More details:
Repository of my distributable bundle is: https://github.com/KdrMkLabs/TicketBundle