添加了Doctrine Entity(Symfony 2.6标准)的列不被原则所认可 [英] Added columns to Doctrine Entity (Symfony 2.6 standard) are not recognized by doctrine
问题描述
类定义:
/ **
* @ ORM\Entity
* @ ORM\Table(name =creature)
* /
class生物实现JsonSerializable {
非典型函数定义:
public function __set $ name,$ value){
$ this-> $ name = $ value;
return $ this;
}
public function jsonSerialize(){
$ json = array();
foreach($ this as $ key => $ value){
if($ key!=attacks){
$ json [$ key] = $ value;
} else {
$ json [$ key] = array(); ($ x = 0; $ x< count($ this-> attacks); $ x ++){
$ json [$ key] [$ x] = array();
$ json [$ key] [$ x] [attack] = $ this-> attacks [$ x] - > getName();
$ json [$ key] [$ x] [bonus] = $ this-> attacks [$ x] - > getBonus();
$ json [$ key] [$ x] [damage] = $ this-> attacks [$ x] - > getDamage();
}
}
}
return $ json;
}
在大多数情况下,这个实体是非常好的。除了我一直以来,我发现我需要再添加3列。所以,我自然地把它添加到我的实体类中:
/ **
* ORM\Column =integer,nullable = true)
* /
protected $ experience;
/ **
* ORM\Column(type =integer,nullable = true)
* /
protected $ cr;
/ **
* ORM\Column(type =integer,nullable = true)
* /
protected $ proficiencybonus;
并试图运行
php app / console generate:doctrine:entities AppBundle
php app / console doctrine:schema:update --force
除了两个命令都认识到我做了任何改变。我尝试清除缓存(dev和prod)并从实体中删除我的自定义代码,但仍然不会添加我的三个新列。我的下一个想法是完全重置我的数据库,但是如果我可以帮助,我不想这么做。
任何人都有任何想法?
您的注释中似乎忘记了 @
:
/ **
* @ ORM\Column(type =integer,nullable = true)
* /
保护$经验;
/ **
* @ ORM\Column(type =integer,nullable = true)
* /
protected $ cr;
/ **
* @ ORM\Column(type =integer,nullable = true)
* /
protected $ proficiencybonus;
I have an entity in my symfony2 app with more than a few attributes. It implements JSONserializable, since all the work on the entity is done on the javascript side, and I have a magic setter function defined so I can loop through the JSON I'm getting from the client and set all of my attributes at once.
The Class definition:
/**
*@ORM\Entity
*@ORM\Table(name="creature")
*/
class Creature implements JsonSerializable {
And the atypical function definitions:
public function __set($name, $value) {
$this->$name = $value;
return $this;
}
public function jsonSerialize() {
$json = array();
foreach($this as $key => $value) {
if($key != "attacks") {
$json[$key] = $value;
} else {
$json[$key] = array();
for($x = 0; $x < count($this->attacks); $x++) {
$json[$key][$x] = array();
$json[$key][$x]["attack"] = $this->attacks[$x]->getName();
$json[$key][$x]["bonus"] = $this->attacks[$x]->getBonus();
$json[$key][$x]["damage"] = $this->attacks[$x]->getDamage();
}
}
}
return $json;
}
For the most part, this entity is working great. Except as I was going along I discovered I needed to add 3 more columns. So, naturally, I added this to my entity class:
/**
*ORM\Column(type="integer", nullable=true)
*/
protected $experience;
/**
*ORM\Column(type="integer", nullable=true)
*/
protected $cr;
/**
*ORM\Column(type="integer", nullable=true)
*/
protected $proficiencybonus;
And attempted to run
php app/console generate:doctrine:entities AppBundle
php app/console doctrine:schema:update --force
Except neither command recognized that I had made any change. I tried clearing my cache(dev and prod) and deleting my custom code from the entity, but it still won't add my three new columns. My next thought is to reset my database completely, but I'm not keen to do that if I can help it.
Anyone have any ideas?
Looks like you forgot the @
in your annotations :
/**
*@ORM\Column(type="integer", nullable=true)
*/
protected $experience;
/**
*@ORM\Column(type="integer", nullable=true)
*/
protected $cr;
/**
*@ORM\Column(type="integer", nullable=true)
*/
protected $proficiencybonus;
这篇关于添加了Doctrine Entity(Symfony 2.6标准)的列不被原则所认可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!