あなたは3対1の関係を必要としますが、これは双方向にすることができます。
/** @Entity */
class Product
{
/** @Column(type="integer") */
private $id;
/** @Column(length=140) */
private $name;
/**
* @OneToMany(targetEntity="ProductFeature", mappedBy="product")
*/
private $features;
public function __construct() {
$this->features = new ArrayCollection();
}
}
/** @Entity */
class ProductFeature
{
/** @Column(type="integer") */
private $id;
/** @Column(length=140) */
private $name;
/**
* @ManyToOne(targetEntity="Product", inversedBy="features")
* @JoinColumn(name="product_id", referencedColumnName="id")
*/
private $product;
/**
* @OneToMany(targetEntity="ProductFeatureVariant", mappedBy="productFeature")
*/
private $variants;
public function __construct() {
$this->variants = new ArrayCollection();
}
}
/** @Entity */
class ProductFeatureVariant
{
/** @Column(type="integer") */
private $id;
/** @Column(length=140) */
private $name;
/**
* @ManyToOne(targetEntity="ProductFeature", inversedBy="variants")
* @JoinColumn(name="product_id", referencedColumnName="id")
*/
private $productFeature;
}
単純な結合を行うことができます。
//select products with a certain color
$qb = $this->entityManager->createQueryBuilder();
$qb
->select('p')
->from('Product', 'p')
->leftJoin('p.features', 'f')
->leftJoin('f.variants', 'v')
->where('v.name = :color')
->setParameter('color', $color);
通常、自分で結合テーブルを作成する必要はありません。関係を使用する(製品と機能、色と機能、サイズなど) – JimL
テーブル名のように見えますが混乱します。ここで私は を期待しています基本的な構造は、製品** **です:ID、Feature_title ** FeatureVariant **:ID、FEATURE_ID、variant_title 決勝の組み合わせ表のようになりますID、名前 **は**特長: ** ProductFeatureVariant **:product_id、feature_id、およびvariant_id –