0

我有这个与 1:m 关系的表,所以一只股票可以有一个或多个 stock_details。这就是我构建实体的方式:

KStock.php

/**
 * @ORM\Table(name="stock")
 * @ORM\Entity(repositoryClass="StockBundle\Entity\Repository\KStockRepository")
 * @Gedmo\SoftDeleteable(fieldName="deletedAt")
 */
class KStock {

    /**
     * @ORM\Id      
     * @ORM\ManyToOne(targetEntity="ProductBundle\Entity\Product", inversedBy="stocks" )      
     * @ORM\JoinColumn(name="product", referencedColumnName="upc")   
     */
    protected $product;

    /**
     * @ORM\Id      
     * @ORM\ManyToOne(targetEntity="CompanyBundle\Entity\Company", inversedBy="companyHasStock" )      
     * @ORM\JoinColumn(name="company", referencedColumnName="id")   
     */
    protected $company;

    /**
     * 
     * @ORM\ManyToOne(targetEntity="ProductBundle\Entity\NCondition", inversedBy="stocks" )      
     * @ORM\JoinColumn(name="kcondition", referencedColumnName="id")   
     */
    protected $condition;

    /**
     * 
     * @ORM\ManyToOne(targetEntity="StockBundle\Entity\NStockStatus", inversedBy="stocks" )      
     * @ORM\JoinColumn(name="status", referencedColumnName="id")   
     */
    protected $status;

    /**
     * @ORM\Column(type="string", length=255, name="sku")
     */
    protected $sku;

    /**
     * @ORM\Column(type="string", length=255)    
     */
    protected $description;

    /**
     * @ORM\ManyToOne(targetEntity="StockBundle\Entity\NUnit")
     * @ORM\JoinColumn(name="unit", referencedColumnName="id")
     */
    protected $unit;

    /**
     *
     * @ORM\Column(type="decimal", precision=4, scale=2)         
     */
    protected $width;

    /**
     *
     * @ORM\Column(type="decimal", precision=4, scale=2)         
     */
    protected $height;

    /**
     *
     * @ORM\Column(type="decimal", precision=4, scale=2)         
     */
    protected $weight;

    /**
     *
     * @ORM\Column(type="decimal", precision=4, scale=2)         
     */
    protected $length;

    /**
     * @ORM\ManyToOne(targetEntity="ProductBundle\Entity\NWeight")
     * @ORM\JoinColumn(name="nweight", referencedColumnName="id")
     */
    protected $nweight;

    /**
     * @ORM\ManyToOne(targetEntity="ProductBundle\Entity\NLength")
     * @ORM\JoinColumn(name="nlength", referencedColumnName="id")
     */
    protected $nlength;

    /**
     * @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\Column(name="deletedAt", type="datetime", nullable=true)
     */
    protected $deletedAt;

    /**
     * @ORM\OneToMany(targetEntity="StockBundle\Entity\StockDetail", mappedBy="stockd")
     */
    protected $sdetail;

    public function setStockDetail(\StockBundle\Entity\StockDetail $stockDetail) {
        $this->sdetail[] = $stockDetail;
    }

    public function getStockDetail() {
        return $this->sdetail;
    }

    public function setProduct(\ProductBundle\Entity\Product $param) {
        $this->product = $param;
    }

    public function getProduct() {
        return $this->product;
    }

    public function setCompany(\CompanyBundle\Entity\Company $param) {
        $this->company = $param;
    }

    public function getCompany() {
        return $this->company;
    }

    public function setCondition(\ProductBundle\Entity\NCondition $condition) {
        $this->condition = $condition;
    }

    public function getCondition() {
        return $this->condition;
    }

    public function setStatus(\StockBundle\Entity\NStockStatus $param) {
        $this->status = $param;
    }

    public function getStatus() {
        return $this->status;
    }

    public function setSku($param) {
        $this->sku = $param;
    }

    public function getSku() {
        return $this->sku;
    }

    public function setDescription($description) {
        $this->description = $description;
    }

    public function getDescription() {
        return $this->description;
    }

    public function setUnit(\StockBundle\Entity\NUnit $unit) {
        $this->unit = $unit;
    }

    public function getUnit() {
        return $this->unit;
    }

    public function setWidth($width) {
        $this->width = $width;
    }

    public function getWidth() {
        return $this->width;
    }

    public function setHeight($height) {
        $this->height = $height;
    }

    public function getHeight() {
        return $this->height;
    }

    public function setWeight($weight) {
        $this->weight = $weight;
    }

    public function getWeight() {
        return $this->weight;
    }

    public function setLength($length) {
        $this->length = $length;
    }

    public function getLength() {
        return $this->length;
    }

    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;
    }

    public function getDeletedAt() {
        return $this->deletedAt;
    }

    public function setDeletedAt($deletedAt) {
        $this->deletedAt = $deletedAt;
    }

    public function setNWeight(\ProductBundle\Entity\NWeight $nweight) {
        $this->nweight = $nweight;
    }

    public function getNWeight() {
        return $this->nweight;
    }

    public function setNLength(\ProductBundle\Entity\NLength $nlength) {
        $this->nlength = $nlength;
    }

    public function getNLength() {
        return $this->nlength;
    }

    public function __toString() {
        return $this->company . ' -- ' . $this->product;
    }

}

StockDetail.php

/**
 * @ORM\Table(name="stock_detail")
 * @ORM\Entity
 * @ORM\Entity(repositoryClass="StockBundle\Entity\Repository\StockDetailRepository")
 * @Gedmo\SoftDeleteable(fieldName="deletedAt")
 */
class StockDetail {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     */
    protected $id;

    /**
     * @ORM\Id      
     * @ORM\ManyToOne(targetEntity="CompanyBundle\Entity\Company")      
     * @ORM\JoinColumn(name="company", referencedColumnName="id")   
     */
    protected $company;

    /**
     * 
     * @ORM\Id 
     * @ORM\ManyToOne(targetEntity="ProductBundle\Entity\NCondition")      
     * @ORM\JoinColumn(name="kcondition", referencedColumnName="id")   
     */
    protected $condition;

    /**
     * 
     * @ORM\Id 
     * @ORM\ManyToOne(targetEntity="ProductBundle\Entity\Product")      
     * @ORM\JoinColumn(name="product", referencedColumnName="upc")   
     */
    protected $product;

    /**
     *
     * @ORM\Column(type="decimal", precision=19, scale=4)         
     */
    protected $price;

    /**
     * @ORM\Column(type="integer")
     */
    protected $amount;

    /**
     *
     * @ORM\Column(type="integer")        
     */
    protected $availability;

    /**
     * @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\Column(name="deletedAt", type="datetime", nullable=true)
     */
    protected $deletedAt;

    /**
     * @ORM\ManyToOne(targetEntity="StockBundle\Entity\KStock", inversedBy = "sdetail")
     * @ORM\JoinColumn(name="stockd", referencedColumnName="id")
     */
    protected $stockd;

    public function setDetail(\StockBundle\Entity\KStock $detail) {
        $this->stockd = $detail;
    }

    public function getDetail() {
        return $this->stockd;
    }

    public function setProduct(\ProductBundle\Entity\Product $product) {
        $this->product = $product;
    }

    public function getProduct() {
        return $this->product;
    }

    public function setCompany(\CompanyBundle\Entity\Company $company) {
        $this->company = $company;
    }

    public function getCompany() {
        return $this->company;
    }

    public function setCondition(\ProductBundle\Entity\NCondition $condition) {
        $this->condition = $condition;
    }

    public function getCondition() {
        return $this->condition;
    }

    public function setAvailability($param) {
        $this->availability = $param;
    }

    public function getAvailability() {
        return $this->availability;
    }

    public function setPrice($param) {
        $this->price = $param;
    }

    public function getPrice() {
        return $this->price;
    }

    public function setAmount($amount) {
        $this->amount = $amount;
    }

    public function getAmount() {
        return $this->amount;
    }

    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;
    }

    public function getDeletedAt() {
        return $this->deletedAt;
    }

    public function setDeletedAt($deletedAt) {
        $this->deletedAt = $deletedAt;
    }

}

在我看来,我正在尝试访问这些值:

{{ entity.getStockDetail.getAmount }}
{{ entity.getStockDetail.getPrice|number_format(2, '.', '') }}

但我得到了这个错误:

渲染模板期间引发异常(“在 'StockBundle\Entity\KStock' 上找不到映射到列 'id' 的字段。该字段不存在或关联存在但它有多个连接列.") 在 ProductBundle:Default:index.html.twig 第 52 行。

关系有什么问题?

4

1 回答 1

1

$stockd尝试从in 中删除以下行StockDetail

 @ORM\JoinColumn(name="stockd", referencedColumnName="id")
于 2013-09-27T13:54:29.833 回答