How do you use yiic to update model files without clobbering changes?

I’m considering using Yii. I have read the blog tutorial, the majority of the Definitive Guide to Yii and brushed over the cookbook. I love how the models are created by examining the table structure and metadata.

I quickly dismissed other frameworks that required defining the database in an external file or even in code. We manage our databases with traditional database tools and we will not be able to modify our workflow to accommodate a framework, the framework needs to accommodate us. So far Yii appears to be appropriately flexible to this end.

One thing that happens in development is schema changes. New tables, new columns on existing tables, even new foreign keys are commonplace. Less common is dropping columns or tables, and even less common is overhauls where tables are redesigned.

With that in mind is there a process in Yii to re-run the model generation code that won’t overwrite changes made to model files? This is a convenient feature in some frameworks like Qcodo and WebObjects. The pattern is to generate an abstract model class and then generate a shell class that extends the generated class (only if the child class doesn’t exist). All references use the child class. This allows customization in the child class and regeneration of the parent model class.

I have searched the documentation and forums for any reference to this usage pattern but I have found nothing. I understand that if this pattern isn’t currently in Yii I may use it myself and update all generated references to the child class but this would get problematic.

Now, I haven’t done a large amount of coding using Yii so there may be something obvious I’m just missing. Maybe this particular pattern isn’t used and something else is instead. I just haven’t seen it.

So, is there a solution to regeneration of model files?

Thanks!

Not that I know, but I’d love that feature too…

Does nobody use Yii for large projects? This problem is extremely common. What is the Yii solution? How do people deal with changing databases?

Manually.

I usually just add rules for the new fields as i add them to the tables.

Same here. Rules should be tuned anyway. I’d never rely solely on a RAD tool. And even though i’m lazy, too, (or maybe because…) it keeps me alert to add these rules manually instead of just adapting some pre-generated ones.

It can be done manually or not.

In some cases I am using an approach similar to the one described from MCToon. I use Yiic for generate a the model class that I declare abstract, and all real models are extending that class.

This is comfortable if you have more than one model for each table, for example if you use this model in different modules (like user or admin) and in a module you have some feature that in the other one ther aren’t.

Using this approach you can share activeLabels, rules, relations, and allows you to regenerate the model.

But I cannot immagine a situation in wich the regenration of model completely resolve the update.

Once you have a new model, but is probably that you will update some view for entry the data about this new field or for show this data.

The Yii approach is comfortable for this kind of update: after adding a field in a table you have to modifiy the model (maybe regenerating it) and update the views that refers to this model (maybe regenerating with crud).

In my experience authomated tools for generate code are confortable, but after using it is anyway a good idea to give a look to this code