whiplashomega whiplashomega - 1 month ago 9
PHP Question

Added columns to Doctrine Entity (Symfony 2.6 standard) are not recognized by doctrine

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?

Answer

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