-
Notifications
You must be signed in to change notification settings - Fork 47
Support for Doctrine Custom Mapping Types seems to be missing #38
Copy link
Copy link
Open
Description
It seems like FixtureGenerator::generateFixtureItemStub doesn't support Doctrine Custom Mapping Types which returns object as a PHP value from convertToPHPValue method rather than \DateTime object.
Following code will fail to generate fixtures from database with error message
The class 'AppBundle\Doctrine\Entity\MyCustomValue' was not found in the chain configured namespaces AppBundle\Entity, Webonaute\DoctrineFixturesGeneratorBundle\Entity.
# app/config/config.yml
# Doctrine Configuration
doctrine:
dbal:
types:
my_custom_value: AppBundle\Doctrine\DBAL\MyCustomValueType
// src/AppBundle/Doctrine/DBAL/MyCustomValueType.php
<?php
namespace AppBundle\Doctrine\DBAL;
use AppBundle\Doctrine\Entity\MyCustomValue;
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class MyCustomValueType extends StringType
{
const TYPE_NAME = 'my_custom_value';
public function convertToPHPValue($value, AbstractPlatform $platform)
{
$convertedValue = parent::convertToPHPValue($value, $platform);
return new MyCustomValue($convertedValue);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
$value = parent::convertToDatabaseValue($value->__toString(), $platform);
return $value;
}
public function getName()
{
return self::TYPE_NAME;
}
}// src/AppBundle/Doctrine/Entity/MyCustomValue.php
namespace AppBundle\Doctrine\Entity;
class MyCustomValue
{
protected $value
public function __construct($value)
{
$this->value = $value;
}
public function __toString()
{
return $this->value;
}
}<?php
// src/AppBundle/Entity/Blog.php
namespace AppBundle\Entity;
use AppBundle\Doctrine\Entity\MyCustomValue;
class Blog
{
/**
* @var MyCustomValue
* @ORM\Column(name="name", type="my_custom_value")
*/
private $name;
public function setName(MyCustomValue $name)
{
$this->name = $name;
return $this;
}
public function getName() : MyCustomValue
{
return $this->name;
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels