Reputation: 762
So. I already have some existing Entity PHP files, which have had their getters and setters done and been applied to the database. Now I want to add a new entity, get it's getters and setters done and applied to the database. This is what my Entity annotation file looks like:
MyEntity.php
<?php
// src/Me/MyBundle/Entity/MyEntity.php
namespace Me\MyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="MyEntity")
*/
class MyEntity
{
/**
* @ORM\Id
* @ORM\Column(type="integer", unique=true)
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $MyEntityID;
}
What commands should I use to do just 1 entity, rather than all of them?
e.g. to do all of them, I do this under PHP CLI:
php app/console doctrine:generate:entities Me\MyBundle
And then, using sudo Bash and then su - www-data
php app/console doctrine:schema:create
(I have to do this as www-data otherwise I get a permission denied from dev.log)
Although that requires me to delete the existing tables. I could use:
php app/console doctrine:schema:update
But that complains unless I use --force
What are the commands I need to create getters and setter for this one, new, entity and add it to the DB.
Thanks.
Upvotes: 1
Views: 2491
Reputation: 10085
For generating getters and setter to single entities you give them in a shorthand notation to the command:
php app/console doctrine:generate:entities MyCustomBundle:User
php app/console doctrine:generate:entities MyCustomBundle/Entity/User
for upgrading existing databases you should take a deep look at the DoctrineMigrationsBundle and generate a migration class, which does the update.
Upvotes: 2