Details
-
Type:
Bug
-
Status:
In Progress
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 2.2.0-RC1
-
Fix Version/s: None
-
Component/s: ORM
-
Security Level: All
-
Labels:None
-
Environment:MAMP
Description
Suppose I have the following entities:
/** * @ORM\Entity * @ORM\Table(name="driver") */ class Driver { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\Column(type="string", length=255); */ private $name; /** * @ORM\OneToMany(targetEntity="DriverRide", mappedBy="driver") */ private $driverRides; }
/** * @ORM\Entity * @ORM\Table(name="driver_ride") */ class DriverRide { /** * @ORM\Id * @ORM\ManyToOne(targetEntity="Driver", inversedBy="driverRides") * @ORM\JoinColumn(name="driver_id", referencedColumnName="id") */ private $driver; /** * @ORM\Id * @ORM\ManyToOne(targetEntity="Car", inversedBy="carRides") * @ORM\JoinColumn(name="car", referencedColumnName="brand") */ private $car; }
/** * @ORM\Entity * @ORM\Table(name="car") */ class Car { /** * @ORM\Id * @ORM\Column(type="string", length=25) * @ORM\GeneratedValue(strategy="NONE") */ private $brand; /** * @ORM\Column(type="string", length=255); */ private $model; /** * @ORM\OneToMany(targetEntity="DriverRide", mappedBy="car") */ private $carRides; }
And want to query for Cars that a Driver drove in:
$qb = $em->createQueryBuilder();
$qb->select('d, dr, c')
->from('Driver', 'd')
->leftJoin('d.driverRides', 'dr')
->leftJoin('dr.car', 'c')
->where('d.id = ?1') /* some Driver id */
->getQuery()->getArrayResult();
Expected results:
I expect to get an array with an index 'driverRides' with an array of Cars (depending on the data of course).
Actual result:
Just an array with Driver data.
When I started doing some testing I found out I get a different result when I add a third column to the DriverRide table that isn't part of the composite primary key.
Now I did get a 'driverRides' array, but with just a single row and not three as I expected to get in my case.
When I removed the composite key and used an auto-generated id-column, everything worked as expected.
Some test data you might want to use:
INSERT INTO `car` (`brand`, `model`) VALUES
('BMW', '7 Series'),
('Crysler', '300'),
('Mercedes', 'C-Class'),
('Volvo', 'XC90');
INSERT INTO `driver` (`id`, `name`) VALUES
(1, 'John Doe'),
(2, 'Foo Bar');
INSERT INTO `driver_ride` (`driver_id`, `car`) VALUES
(1, 'Crysler'),
(1, 'Mercedes'),
(1, 'Volvo'),
(2, 'BMW');
Can you update to at least 2.2.1 and try again, because this fix here http://www.doctrine-project.org/jira/browse/DDC-1652 look like it could be related to your problem.