我有三个实体:product
,这是关系的media
结果。这是每个实体:product_has_media
n:m
Product.php
namespace ProductBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
* @ORM\Table(name="product")
*/
class Product {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255)
*/
protected $name;
/**
* @ORM\Column(type="string", length=255)
*/
protected $description;
/**
* @ORM\Column(type="smallint")
*/
protected $age_limit;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="created", type="datetime")
*/
protected $created;
/**
* @Gedmo\Timestampable(on="update")
* @ORM\Column(name="modified", type="datetime")
*/
protected $modified;
/**
* @ORM\ManyToMany(targetEntity="CategoryBundle\Entity\Category", inversedBy="products")
* @ORM\JoinTable(name="product_has_category")
*/
protected $categories;
/**
* @ORM\ManyToMany(targetEntity="ProductBundle\Entity\ProductDetail", inversedBy="products_details")
* @ORM\JoinTable(name="product_detail_has_product")
*/
protected $details;
/**
* @ORM\OneToMany(targetEntity="StockBundle\Entity\KStock", mappedBy="sku")
*/
protected $stocks;
/**
* @ORM\OneToMany(targetEntity="ProductBundle\Entity\ProductHasMedia", mappedBy="product")
*/
protected $medias;
public function __construct() {
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
$this->details = new \Doctrine\Common\Collections\ArrayCollection();
$this->stocks = new \Doctrine\Common\Collections\ArrayCollection();
$this->medias = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getId() {
return $this->id;
}
public function setName($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
public function setDescription($description) {
$this->description = $description;
}
public function getCondition() {
return $this->condition;
}
public function setAgeLimit($age_limit) {
$this->age_limit = $age_limit;
}
public function getAgeLimit() {
return $this->age_limit;
}
public function setMedias(\MediaBundle\Entity\Media $medias) {
$this->medias[] = $medias;
}
public function getMedias() {
return $this->medias;
}
public function setCreated($created) {
$this->created = $created;
}
public function getCreated() {
return $this->created;
}
public function setModified($modified) {
$this->modified = $modified;
}
public function getModified() {
return $this->modified;
}
}
ProductHasMedia.php
<?php
namespace ProductBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="product_has_media")
*/
class ProductHasMedia {
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="ProductBundle\Entity\Product")
* @ORM\JoinColumn(name="product", referencedColumnName="id")
*/
protected $product;
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="MediaBundle\Entity\Media")
* @ORM\JoinColumn(name="media", referencedColumnName="id")
*/
protected $media;
public function setProduct(\ProductBundle\Entity\Product $product) {
$this->product = $product;
}
public function getProduct() {
return $this->product;
}
public function setMedia(\MediaBundle\Entity\Media $media) {
$this->media = $media;
}
public function getMedia() {
return $this->media;
}
}
media
存在一个名为的列,url
我需要让它只id
具有product
. 任何人都可以帮助我完成这项工作吗?我迷路了