0

私はこれを 1:m の関係を持つテーブルに持っているので、1 つの株が 1 つまたは複数の 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, '.', '') }}

しかし、私はこのエラーが発生しました:

テンプレートのレンダリング中に例外がスローされました (「列 'id' にマップされている 'StockBundle\Entity\KStock' のフィールドが見つかりません。フィールドが存在しないか、関連付けが存在しますが、複数の結合列があります。 .") ProductBundle:Default:index.html.twig の 52 行目。

関係の何が悪いのですか?

4

1 に答える 1

1

から次の行を削除してみて$stockdくださいStockDetail

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