我试图通过运行任务来生成一个简单的 Doctrine2 CRUD,php app/console doctrine:generate:crud
但在它结束之前我收到了这个错误:
[Doctrine\ORM\Mapping\MappingException] 在“ProductBundle\Entity\ListHasProduct#list”中找不到目标实体 ProductBundle\Entity\KList。
如果在我的实体中我与该实体没有关系,它为什么要寻找它?这是我的实体代码:
<?php
namespace Wuelto\BankRulesBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Table(name="bank_rules")
* @ORM\Entity
* @Gedmo\SoftDeleteable(fieldName="deletedAt")
*/
class BankRules {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
*
* @ORM\ManyToOne(targetEntity="BankBundle\Entity\NBank" )
* @ORM\JoinColumn(name="n_bank", referencedColumnName="id")
*/
protected $n_bank;
/**
* @ORM\Column(type="string", length=255)
*/
protected $regex;
/**
* @ORM\Column(type="text")
*/
protected $action;
/**
* @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;
public function getId() {
return $this->id;
}
public function setRegex($regex) {
$this->regex = $regex;
return true;
}
public function getRegex() {
return $this->regex;
}
public function setAction($action) {
$this->action = $action;
}
public function getAction() {
return $this->action;
}
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;
}
}
我该如何解决这个问题?
更新 1
ListHastProduct
我通过在实体上修复它来修复第一个错误:
/**
* @ORM\ManyToOne(targetEntity="UserBundle\Entity\KList", inversedBy="products" )
* @ORM\JoinColumns(@ORM\JoinColumn(name="kuser", referencedColumnName="kuser"),
* @ORM\JoinColumn(name="klist", referencedColumnName="name"))
*/
protected $list;
但现在我得到了另一个错误:
[Doctrine\ORM\Mapping\MappingException] 实体 ShoppingBundle\Entity\BillDetail 中的复合主键不允许使用单个 id
这是我的BillDetail
定义:
<?php
namespace ShoppingBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
* @ORM\Table(name="bill_detail")
*/
class BillDetail {
/**
* @ORM\Id
* @ORM\Column(type="int",length=11)
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="ShoppingBundle\Entity\Transaction")
* @ORM\JoinColumn(name="ktransaction", referencedColumnName="id")
*/
protected $transaction;
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="UserBundle\Entity\User")
* @ORM\JoinColumn(name="kuser", referencedColumnName="id")
*/
protected $user;
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="CatalogBundle\Entity\KCatalog")
* @ORM\JoinColumn(name="kcatalog", referencedColumnName="id")
*/
protected $catalog;
/**
* @ORM\Column(type="decimal")
*/
protected $amount;
/**
* @ORM\Column(type="integer")
*/
protected $status;
/**
* @ORM\Column(name="created", type="datetime")
* @Gedmo\Timestampable(on="create")
*/
protected $created;
/**
* @ORM\Column(name="modified", type="datetime")
* @Gedmo\Timestampable(on="update")
*/
protected $modified;
public function getId() {
return $this->id;
}
public function setUser(\UserBundle\Entity\User $user) {
$this->user = $user;
}
public function getUser() {
return $this->user;
}
public function setCatalog(\CatalogBundle\Entity\KCatalog $catalog) {
$this->catalog = $catalog;
}
public function getCatalog() {
return $this->catalog;
}
public function setTransaction(\ShoppingBundle\Entity\Transaction $transaction) {
$this->transaction = $transaction;
}
public function getTransaction() {
return $this->transaction;
}
public function setAmount($amount) {
$this->amount = $amount;
}
public function getAmount() {
return $this->amount;
}
public function setStatus($status) {
$this->status = $status;
}
public function getStatus() {
return $this->status;
}
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;
}
}