How can I add a column to a Database table without overwriting the classes already generated? (Doctrine) What files do I have to edit?
If I simply add the column in the database, I can't use the set and get functions of Doctrine ORM.
How can I add a column to a Database table without overwriting the classes already generated? (Doctrine) What files do I have to edit?
If I simply add the column in the database, I can't use the set and get functions of Doctrine ORM.
You should never edit the base classes (BaseFoo.class.php) as these get overwritten everytime you generate the models from the schema. The other files are never overwritten so it's safe to edit.
Use doctrine migrations. It allows you to modify your schema, update the database and your model without also losing the existing data in your database (in case it is relevant).
http://www.symfony-project.org/doctrine/1_2/en/07-Migrations
Applicable for symfony 1.4 too
Doctrine 1.2:
Go to models folder, open generated class that reflects table to which you have added a column. Add
to
setTableDefinition
method.Note, that your changes will be overwritten on
generate-models
, so make sure you populate it to YAML/DB schemaSee Doctrine Models Definition Manual for reference.
Doctrine 2
Samples given for
Annotations Driver
, see Doctrine2 manual for other XML and YAML drivers Just add new property to your@Entity
class with@Column
annotation on it: