Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c7bb5a

Browse files
Merge pull request doctrine#7828 from andrews05/andrews05-jti-properties
Fix for TransientMetadata on joined subclass
2 parents 0273449 + f2624e9 commit 6c7bb5a

2 files changed

Lines changed: 75 additions & 1 deletion

File tree

lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\ORM\Mapping\ManyToManyAssociationMetadata;
1616
use Doctrine\ORM\Mapping\ToManyAssociationMetadata;
1717
use Doctrine\ORM\Mapping\ToOneAssociationMetadata;
18+
use Doctrine\ORM\Mapping\TransientMetadata;
1819
use Doctrine\ORM\Utility\PersisterHelper;
1920
use function array_combine;
2021
use function array_keys;
@@ -433,7 +434,8 @@ protected function getInsertColumnList()
433434

434435
foreach ($this->class->getPropertiesIterator() as $name => $property) {
435436
if (($property instanceof FieldMetadata && ($property->isVersioned() || $this->class->isInheritedProperty($name)))
436-
|| ($property instanceof AssociationMetadata && $this->class->isInheritedProperty($name))
437+
|| ($property instanceof AssociationMetadata && $this->class->isInheritedProperty($name)
438+
|| $property instanceof TransientMetadata)
437439
/*|| isset($this->class->embeddedClasses[$name])*/) {
438440
continue;
439441
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\ORM\Functional\Ticket;
6+
7+
use Doctrine\ORM\Annotation as ORM;
8+
use Doctrine\Tests\OrmFunctionalTestCase;
9+
10+
/**
11+
* @group GH-7824
12+
*/
13+
class GH7824Test extends OrmFunctionalTestCase
14+
{
15+
protected function setUp() : void
16+
{
17+
parent::setUp();
18+
$this->schemaTool->createSchema([
19+
$this->em->getClassMetadata(GH7824Main::class),
20+
$this->em->getClassMetadata(GH7824Child::class),
21+
]);
22+
}
23+
24+
/**
25+
* Verifies that joined subclasses can contain non-ORM properties.
26+
*/
27+
public function testIssue()
28+
{
29+
// Test insert
30+
$child = new GH7824Child();
31+
$child->name = 'Sam';
32+
$child->someProperty = 'foo';
33+
$this->em->persist($child);
34+
$this->em->flush();
35+
self::assertEquals($child->someProperty, 'foo');
36+
37+
// Test update
38+
$child->name = 'Bob';
39+
$this->em->flush();
40+
$this->em->clear();
41+
42+
// Test find
43+
$child = $this->em->getRepository(GH7824Child::class)->find(1);
44+
self::assertEquals($child->name, 'Bob');
45+
self::assertEquals($child->someProperty, null);
46+
}
47+
}
48+
49+
/**
50+
* @ORM\Entity
51+
* @ORM\InheritanceType("JOINED")
52+
* @ORM\DiscriminatorMap({"child" = "Doctrine\Tests\ORM\Functional\Ticket\GH7824Child"})
53+
*/
54+
abstract class GH7824Main
55+
{
56+
/**
57+
* @ORM\Id
58+
* @ORM\Column(type="integer")
59+
* @ORM\GeneratedValue
60+
*/
61+
public $id;
62+
}
63+
64+
/**
65+
* @ORM\Entity
66+
*/
67+
class GH7824Child extends GH7824Main
68+
{
69+
/** @ORM\Column(type="string") */
70+
public $name;
71+
public $someProperty; // Not a column
72+
}

0 commit comments

Comments
 (0)