notification-bundle: Overriding entity doesn't work
Hello, I tried overriding the Notification entity following your guide:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Mgilet\NotificationBundle\Entity\NotificationInterface;
use Mgilet\NotificationBundle\Model\Notification as NotificationModel;
/**
* Notification
*
* @ORM\Entity(repositoryClass="AppBundle\Repository\NotificationRepository")
*/
class Notification extends NotificationModel implements NotificationInterface
{
/**
* @var string
*
* @ORM\Column(name="`type`", type="string", length=255)
*/
private $type;
/**
* @var string|null
*
* @ORM\Column(name="sender", type="string", length=255, nullable=true)
*/
private $sender;
/**
* Set type.
*
* @param string $type
*
* @return Notification
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type.
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Set sender.
*
* @param string|null $sender
*
* @return Notification
*/
public function setSender($sender = null)
{
$this->sender = $sender;
return $this;
}
/**
* Get sender.
*
* @return string|null
*/
public function getSender()
{
return $this->sender;
}
}
Unfortunately it’s not working as it tries to create the table twice:
mysite git:(master) ✗ sf doctrine:schema:update --dump-sql | highlight -l sql
In SchemaException.php line 108:
The table with name 'mysite.notification' already exists.
doctrine:schema:update [--complete] [--dump-sql] [-f|--force] [--em [EM]] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
Looking at the output it’s trying to execute the query twice. This is my config:
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
dql:
numeric_functions:
rand: DoctrineExtensions\Query\Mysql\Rand
orm:
resolve_target_entities:
Mgilet\NotificationBundle\Entity\Notification: AppBundle\Entity\Notification
Thanks!
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 18 (8 by maintainers)
Hi @emulienfou this is a great idea !
However I don’t use the bundle anymore and don’t have much time to make the changes…
Make me a pull request and I’ll try and merge it 😃
Hi @maximilienGilet, so clearly there is an issue right here with the bundle when you are trying to override the default entities. With the actual code, Doctrine find 2 entities with the same table name
notification
and throw an exception.The best way should be to make do a refactoring and provide 3 models classes (
Notification
,NotifiableEntity
andNotifiableNotification
).For Symfony Flex users, it will be perfect to create a recipe who provide the entity classes.
However for the others they will need to create the 3 entity classes manually.
@maximilienGilet What do you think about this idea?