product_item_sortorderテーブルのproduct_itemテーブルとtoolboxItemIdに基づいて、一致するローを選択しようとしています。 Doctrine 2複数のjoinColumnを持つManyToOne
SELECT pi.*, pis.* FROM product_item pi
LEFT JOIN product_item_sortorder pis
ON pi.productId = pis.productId
AND pi.toolboxItemId = pis.toolboxItemId
WHERE pi.productId = 6
は、私は以下のようにそれのためにDQLを書いた:指定されたProductIDのためになる、通常のSQLで
その後
$this->_em->createQuery(
'SELECT pi
FROM Entities\ProductItem pi
LEFT JOIN pi.sequence s
WHERE pi.product = ?1'
);
私はSQL以下得ればI出力$ query- > getSQL():
SELECT p0_.id AS id0, p0_.productId AS productId1, p0_.priceGroupId AS priceGroupId2, p0_.toolboxItemId AS toolboxItemId3, p0_.levelId AS levelId4, p0_.parentId AS parentId5, p0_.productId AS productId6, p0_.toolboxItemId AS toolboxItemId7 FROM product_item p0_ LEFT JOIN product_item_sortorder p1_ ON p0_.productId = p1_. AND p0_.toolboxItemId = p1_. WHERE p0_.productId = ? ORDER BY p0_.id ASC
referencedColumnNamesが発見されていないあなたが見ることができるように:
012 PRODUCT_ITEMテーブルののLEFT JOIN product_item_sortorder p1_ ON p0_.productId = p1_. AND p0_.toolboxItemId = p1_.
詳細:product_item_sortorderテーブルの
+-----+-----------+---------------+
| id | productId | toolboxItemId |
+-----+-----------+---------------+
| 467 | 1 | 3 |
| 468 | 1 | 10 |
| 469 | 1 | 20 |
| 470 | 1 | 4 |
| 471 | 1 | 10 |
+-----+-----------+---------------+
詳細:
+-----+-----------+---------------+----------+
| id | productId | toolboxItemId | sequence |
+-----+-----------+---------------+----------+
| 452 | 1 | 3 | 1 |
| 457 | 1 | 4 | 6 |
| 474 | 1 | 20 | 4 |
+-----+-----------+---------------+----------+
ProductItemエンティティ
<?php
/**
* @Entity(repositoryClass="Repositories\ProductItem")
* @Table(name="product_item")
*/
class ProductItem
{
...
/**
* @ManyToOne(targetEntity="ProductItemSortorder")
* @JoinColumns({
* @JoinColumn(name="productId", referencedColumnName="productId"),
* @JoinColumn(name="toolboxItemId", referencedColumnName="toolboxItemId")
* })
*/
protected $sequence;
...
?>
ProductItemSortOrderエンティティ
<?php
/**
* @Entity(repositoryClass="Repositories\ProductItemSortorder")
* @Table(name="product_item_sortorder")
*/
class ProductItemSortorder
{
...
/**
* @ManyToOne(targetEntity="Product")
* @JoinColumn(name="productId", referencedColumnName="id")
*/
protected $product;
/**
* @ManyToOne(targetEntity="ToolboxItem")
* @JoinColumn(name="toolboxItemId", referencedColumnName="id")
*/
protected $toolboxItem;
...
}
?>
ビット以下で実行したいクエリを見ることができます – tom