views:

225

answers:

3

What is the a standard way of adding new model to my app built on Symfony + Doctrine while maintaining all previous models and their meta-data (like relationships).

What am I really looking for: A command / procedure that will be equivalent of ./script/generate model FooModel in Ruby on Rails (which does not have any sort of reset db / reset models while generating)

If these two are different things, and I am chasing the wrong ghost (I would like to think I am not), please let me know.

EDIT: Updated the question.

+3  A: 

You shouldn't be overriding the base classes, as these will be mostly be auto-generated whenever you do build:all or doctrine:build-model etc. Use the classes generated in the lib/model directory eg YourModel.class.php if you want to add new methods etc. Then your new models will be generated alongside your existing ones.

richsage
You are right, I removed them all from Base classes. Now managing it through schema.yml
Swanand
+1  A: 

Standard process is to add the new model and any relationships it requires to schema.yml

Then do ./symfony doctrine:build-all (or :build --all for symfony 1.3/1.4)

As richsage says, you shouldn't be editing the base classes, so this operation is totally non destructive.

Doctrine also has functionality for migrations so that you an update the database schema easily as you deploy the new code into production:

http://www.doctrine-project.org/documentation/cookbook/1%5F0/en/symfony-and-doctrine-migrations

Newer versions of doctrine (1.1 +, symfony 1.3+) include the generate-migrations-diff task, which can create migrations for you. This is covered very well here:

http://stackoverflow.com/questions/1855925/extra-changecolumns-in-doctrine-generate-migrations-diff

[edit: the author of the question above has copy/pasted it below as well now]

benlumley
A: 

The generate-migrations-diff doesn't diff two different yaml files. It actually compares your models and your yaml file and then generates a migration based on the differences. If you start from a db that is in sync with your yaml and classes, your workflow to make schema changes should be:

  1. Change yaml file
  2. Run generate-migrations-diff to diff your current (changed) yaml with your (unchanged) models. This will generate a migrations file in your doctrine/migrations directory (or whatever migrations_path is set to in your doctrine config).
  3. Run migrate to run the migration created in step 2 and modify your database
  4. Run generate-models-yaml to generate new classes based on your yaml file. These go where you've specified your generated models go (models_path in your doctrine config).
  5. Run generate-sql to generate a SQL file. This will go where your doctrine sql_path config is set to.
Chris Williams