1
0
mirror of synced 2024-12-05 03:06:05 +03:00

Merge pull request #1321 from vvh-empora/master

embeddedClasses support...
This commit is contained in:
Marco Pivetta 2015-03-10 21:53:05 +01:00
commit a3f9f153dd
6 changed files with 302 additions and 1 deletions

View File

@ -546,7 +546,8 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
if (isset($this->class->fieldMappings[$name]['inherited'])
&& ! isset($this->class->fieldMappings[$name]['id'])
|| isset($this->class->associationMappings[$name]['inherited'])
|| ($this->class->isVersioned && $this->class->versionField == $name)) {
|| ($this->class->isVersioned && $this->class->versionField == $name)
|| isset($this->class->embeddedClasses[$name])) {
continue;
}

View File

@ -0,0 +1,37 @@
<?php
namespace Doctrine\Tests\Models\DDC3597;
use Doctrine\Tests\Models\DDC3597\Embeddable\DDC3597Dimension;
/**
* Description of Image
*
* @author Volker von Hoesslin <volker.von.hoesslin@empora.com>
* @Entity
*/
class DDC3597Image extends DDC3597Media {
const CLASSNAME = __CLASS__;
/**
* @var DDC3597Dimension
* @Embedded(class = "Doctrine\Tests\Models\DDC3597\Embeddable\DDC3597Dimension", columnPrefix = false)
*/
private $dimension;
/**
* @param string $distributionHash
*/
function __construct($distributionHash) {
parent::__construct($distributionHash);
$this->dimension = new DDC3597Dimension();
}
/**
* @return DDC3597Dimension
*/
public function getDimension() {
return $this->dimension;
}
}

View File

@ -0,0 +1,76 @@
<?php
namespace Doctrine\Tests\Models\DDC3597;
/**
* Description of Media
*
* @author Volker von Hoesslin <volker.von.hoesslin@empora.com>
* @Entity
*/
abstract class DDC3597Media extends DDC3597Root {
const CLASSNAME = __CLASS__;
/**
* @var string
*
* @Column
*/
private $distributionHash;
/**
* @var integer
*
* @Column
*/
private $size = 0;
/**
* @var string
* @Column
*/
private $format;
function __construct($distributionHash) {
$this->distributionHash = $distributionHash;
}
/**
* @return string
*/
public function getDistributionHash() {
return $this->distributionHash;
}
/**
* @return int
*/
public function getSize() {
return $this->size;
}
/**
* @param int $size
*/
public function setSize($size) {
$this->size = $size;
}
/**
* @return string
*/
public function getFormat() {
return $this->format;
}
/**
* @param string $format
*/
public function setFormat($format) {
$this->format = $format;
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace Doctrine\Tests\Models\DDC3597;
use Doctrine\ORM\Mapping\DiscriminatorMap;
/**
* Description of Root
*
* @Entity
*
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discriminator", type="string")
* @DiscriminatorMap({ "image" = "DDC3597Image"})
* @HasLifecycleCallbacks
*/
abstract class DDC3597Root {
const CLASSNAME = __CLASS__;
/**
* @var int
*
* @Column(name="id", type="integer", nullable=false)
* @Id
* @GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var \DateTime
* @Column(name="created_at", type="datetime", nullable=false)
*/
protected $createdAt = null;
/**
* @var \DateTime
* @Column(name="updated_at", type="datetime", nullable=false)
*/
protected $updatedAt = null;
/**
* Set createdAt
*
* @PrePersist
*/
public function _prePersist() {
$this->updatedAt = $this->createdAt = new \DateTime();
}
/**
* Set updatedAt
*
* @PreUpdate
*/
public function _preUpdate() {
$this->updatedAt = new \DateTime();
}
/**
* @return int
*/
public function getId() {
return (int)$this->id;
}
/**
* @return \DateTime
*/
public function getCreatedAt() {
return $this->createdAt;
}
/**
* @return \DateTime
*/
public function getUpdatedAt() {
return $this->updatedAt;
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace Doctrine\Tests\Models\DDC3597\Embeddable;
/**
* Description of DDC3597Dimension
*
* @Embeddable
*/
class DDC3597Dimension {
/**
* @var int
* @Column(type="integer", name="width")
*/
private $width;
/**
* @var int
* @Column(type="integer", name="height")
*/
private $height;
function __construct($width = 0, $height = 0) {
$this->setWidth($width);
$this->setHeight($height);
}
/**
* @return int
*/
public function getWidth() {
return $this->width;
}
/**
* @param int $width
*/
public function setWidth($width) {
$this->width = (int)$width;
}
/**
* @return int
*/
public function getHeight() {
return $this->height;
}
/**
* @param int $height
*/
public function setHeight($height) {
$this->height = (int)$height;
}
}

View File

@ -0,0 +1,51 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\Models\DDC3597\DDC3597Image;
use Doctrine\Tests\Models\DDC3597\DDC3597Media;
use Doctrine\Tests\Models\DDC3597\DDC3597Root;
/**
* @group DDC-117
*/
class DDC3597Test extends \Doctrine\Tests\OrmFunctionalTestCase {
protected function setUp() {
parent::setUp();
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(DDC3597Root::CLASSNAME),
$this->_em->getClassMetadata(DDC3597Media::CLASSNAME),
$this->_em->getClassMetadata(DDC3597Image::CLASSNAME)
));
}
/**
* @group DDC-3597
*/
public function testSaveImageEntity() {
$imageEntity = new DDC3597Image('foobar');
$imageEntity->setFormat('JPG');
$imageEntity->setSize(123);
$imageEntity->getDimension()->setWidth(300);
$imageEntity->getDimension()->setHeight(500);
$this->_em->persist($imageEntity);
$this->_em->flush(); //before this fix, it will fail with a exception
$this->_em->clear();
//request entity
$imageEntity = $this->_em->find(DDC3597Image::CLASSNAME, $imageEntity->getId());
$this->assertInstanceOf(DDC3597Image::CLASSNAME, $imageEntity);
//cleanup
$this->_em->remove($imageEntity);
$this->_em->flush();
$this->_em->clear();
//check delete
$imageEntity = $this->_em->find(DDC3597Image::CLASSNAME, $imageEntity->getId());
$this->assertNull($imageEntity);
}
}