私はそれらのエンティティを持っています:
最初: ProductCupMain -> 製品のように
<?php
namespace xxx\Security\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* xxx\Security\Entity\ProductCupMain
*
* @ORM\Table(name="product_cup_main")
* @ORM\Entity
*/
class ProductCupMain
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string $name
*
* @ORM\Column(name="name", type="string", length=45, nullable=true)
*/
private $name;
/**
* @var string $image
*
* @ORM\Column(name="image", type="string", length=128, nullable=true)
*/
private $image;
/**
* @var string $pdf
*
* @ORM\Column(name="pdf", type="string", length=128, nullable=true)
*/
private $pdf;
/**
* @var ProductCategories
*
* @ORM\ManyToMany(targetEntity="ProductCategories", inversedBy="productCupMain")
* @ORM\JoinTable(name="product_cup_main_has_product_categories",
* joinColumns={
* @ORM\JoinColumn(name="product_cup_main_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="product_categories_id", referencedColumnName="id")
* }
* )
*/
private $productCategories;
2番目: ProductCategories -> like Categories
<?php
namespace xxx\Security\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* xxx\Security\Entity\ProductCategories
*
* @ORM\Table(name="product_categories")
* @ORM\Entity
*/
class ProductCategories
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string $name
*
* @ORM\Column(name="name", type="string", length=45, nullable=false)
*/
private $name;
/**
* @var string $image
*
* @ORM\Column(name="image", type="string", length=100, nullable=true)
*/
private $image;
/**
* @var string $shortname
*
* @ORM\Column(name="shortname", type="string", length=164, nullable=false)
*/
private $shortname;
/**
* @var integer $position
*
* @ORM\Column(name="position", type="integer", nullable=false)
*/
private $position;
/**
* @var ProductCupMain
*
* @ORM\ManyToMany(targetEntity="ProductCupMain", mappedBy="productCategories")
*/
private $productCupMain;
だから、私は多くの製品を多くのカテゴリに保存したいと考えています。(ManyToMany 関係) 私の問題は位置です。製品には、カテゴリ内のさまざまな位置があります。
次のようなリレーションの位置を保存したい:
http://i.stack.imgur.com/Z0gzw.jpg
getPositionInCategory($categoryId) のようなメソッドが必要です。ここで正しい位置を取得できます。手伝って頂けますか ?
さらに、ここで同様の問題を見つけましたが、適切な解決策を得ることができません。
編集1
@mbinette からの解決策: 参照用に 3 番目のエンティティを作成しました。そうですか?
//ProductCategoryReference
<?php
namespace xxx\Security\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* xxx\Security\Entity\ProductCategoryReference
*
* @ORM\Table(name="product_cup_main_has_product_categories")
* @ORM\Entity
*/
class ProductCategoryReference
{
/**
* @ORM\ManyToOne(targetEntity="ProductCupMain", inversedBy="categoriesHavetheProduct")
*/
private $prductCupMain;
/**
* @ORM\ManyToOne(targetEntity="ProductCategories", inversedBy="productsInCategory")
*/
private $productsCategorie;
/**
* @ORM\Column(name="postionInCategorie", type="integer", length=164, nullable=false)
*/
private $postionInCategorie;
public function getProductCupMain()
{
return $this->prductCupMain;
}
public function setProductCupMain($prductCupMain)
{
$this->prductCupMain = $prductCupMain;
}
public function getProductsCategorie()
{
return $this->productsCategorie;
}
public function setProductsCategorie($productsCategorie)
{
$this->productsCategorie = $productsCategorie;
}
public function getPostionInCategorie()
{
return $this->productsCategorie;
}
public function setPostionInCategorie($postionInCategorie)
{
$this->postionInCategorie = $postionInCategorie;
}
}
しかし、product エンティティと category エンティティはどうなるでしょうか。
製品エンティティ:
/**
* @var CategoryHavetheProduct
*
* @OneToMany(targetEntity="ProductCategoryReference", mappedBy="productCupMain")
*
**/
private $categoriesHavetheProduct;
//Please show me the getter and setter methods
カテゴリ エンティティ:
/**
* @var ProductsInCategory
*
* @OneToMany(targetEntity="ProductCategoryReference", mappedBy="productsCategorie")
*
**/
private $productsInCategory;
//Please show me the getter and setter methods