DDC-3228: ORM\Tools\Export\Driver\PhpExporter.php does not properly export manyToOne associations #3996

Closed
opened 2026-01-22 14:33:22 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 24, 2014).

Originally assigned to: @Majkl578 on GitHub.

Jira issue originally created by user bigdan@gmail.com:

PhpExporter.php fails to check the association for manyToOne/oneToOne and exports all associations as oneToOne.

See https://github.com/doctrine/doctrine2/tree/master/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php#L116 where oneToOne is hardcoded if the bitmask matches either manyToOne or oneToOne.

As opposed to YamlExporter.php:

https://github.com/doctrine/doctrine2/tree/master/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php#L165

Which does roughly the same thing, but then properly sets the association type by checking the actual association on lines 186 through one 190:

https://github.com/doctrine/doctrine2/tree/master/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php#L186-L190

Originally created by @doctrinebot on GitHub (Jul 24, 2014). Originally assigned to: @Majkl578 on GitHub. Jira issue originally created by user bigdan@gmail.com: PhpExporter.php fails to check the association for manyToOne/oneToOne and exports all associations as oneToOne. See https://github.com/doctrine/doctrine2/tree/master/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php#L116 where oneToOne is hardcoded if the bitmask matches either manyToOne or oneToOne. As opposed to YamlExporter.php: https://github.com/doctrine/doctrine2/tree/master/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php#L165 Which does roughly the same thing, but then properly sets the association type by checking the actual association on lines 186 through one 190: https://github.com/doctrine/doctrine2/tree/master/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php#L186-L190
admin added the BugWon't Fix labels 2026-01-22 14:33:22 +01:00
admin closed this issue 2026-01-22 14:33:22 +01:00
Author
Owner

@zorji commented on GitHub (Dec 18, 2015):

I am having the same issue.

To reproduce, use the following annotated entities

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class BlogPost
{
    /**
     * @ORM\Id
     * @ORM\Column(type="guid")
     * @ORM\GeneratedValue(strategy="UUID")
     * @var string
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="BlogUser")
     * @var BlogUser
     */
    protected $creator;
}

/**
 * @ORM\Entity
 */
class BlogUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="guid")
     * @ORM\GeneratedValue(strategy="UUID")
     * @var string
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     * @var string
     */
    protected $name;
}

Run $ ./vendor/bin/doctrine orm:convert:mapping php ./mapping

The converted PHP mapping

use Doctrine\ORM\Mapping\ClassMetadataInfo;

$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
$metadata->setPrimaryTable(array(
   'name' => 'BlogPost',
  ));
$metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
$metadata->mapField(array(
   'fieldName' => 'id',
   'type' => 'guid',
   'scale' => 0,
   'length' => NULL,
   'unique' => false,
   'nullable' => false,
   'precision' => 0,
   'id' => true,
   'columnName' => 'id',
  ));
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_UUID);
$metadata->mapOneToOne(array( // <<< THE ISSUE
   'fieldName' => 'creator',
   'targetEntity' => 'BlogUser',
   'cascade' => 
   array(
   ),
   'fetch' => 2,
   'mappedBy' => NULL,
   'inversedBy' => NULL,
   'joinColumns' => 
   array(
   0 => 
   array(
    'name' => 'creator_id',
    'referencedColumnName' => 'id',
   ),
   ),
   'orphanRemoval' => false,
  ));
@zorji commented on GitHub (Dec 18, 2015): I am having the same issue. To reproduce, use the following annotated entities ``` use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity */ class BlogPost { /** * @ORM\Id * @ORM\Column(type="guid") * @ORM\GeneratedValue(strategy="UUID") * @var string */ protected $id; /** * @ORM\ManyToOne(targetEntity="BlogUser") * @var BlogUser */ protected $creator; } /** * @ORM\Entity */ class BlogUser { /** * @ORM\Id * @ORM\Column(type="guid") * @ORM\GeneratedValue(strategy="UUID") * @var string */ protected $id; /** * @ORM\Column(type="string") * @var string */ protected $name; } ``` Run `$ ./vendor/bin/doctrine orm:convert:mapping php ./mapping` The converted PHP mapping ``` use Doctrine\ORM\Mapping\ClassMetadataInfo; $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); $metadata->setPrimaryTable(array( 'name' => 'BlogPost', )); $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT); $metadata->mapField(array( 'fieldName' => 'id', 'type' => 'guid', 'scale' => 0, 'length' => NULL, 'unique' => false, 'nullable' => false, 'precision' => 0, 'id' => true, 'columnName' => 'id', )); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_UUID); $metadata->mapOneToOne(array( // <<< THE ISSUE 'fieldName' => 'creator', 'targetEntity' => 'BlogUser', 'cascade' => array( ), 'fetch' => 2, 'mappedBy' => NULL, 'inversedBy' => NULL, 'joinColumns' => array( 0 => array( 'name' => 'creator_id', 'referencedColumnName' => 'id', ), ), 'orphanRemoval' => false, )); ```
Author
Owner

@Majkl578 commented on GitHub (Dec 19, 2017):

ORM\Tools\Export\Driver\PhpExporter will be dropped in Doctrine 3.0.

@Majkl578 commented on GitHub (Dec 19, 2017): ORM\Tools\Export\Driver\PhpExporter will be dropped in Doctrine 3.0.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3996