I initially posted this as an issue on github, but the forum might get better exposure/discussion.
I think we can all agree that model building with dev tools has some problems. Mainly losing comments and changes to setters and getters.
I would like to propose a better structure, which has actually worked for me very well for the last few months. This is based on what symfony 1.4 does.
Every model consists of two classes (using User model as example):
- "RawUser"
- "User" which extends "RawUser"
Both are generated by the dev tools, but only RawUser is overwritten when the --force parameter is used. This way you are free to make any changes to setters / getters etc in the "Model" class without having to worry about your code being lost. It also helps de-clutter the Model class, since it doesn't contain any variable declarations or setters.
You can test it here: https://github.com/nazwa/phalcon-devtools
I would love to hear what others think about this approach.
Edit Two thing to consider:
- Name of the 'base' class. Is 'RawXX' a good choice? If i remember correctly I had a conflict with 'BaseXX', which is why I didn't use it.
- Should the 'base' class be in the same folder or in a sub folder of the models dir. How can the autoload be improved to remove the extra variable. Maybe assume that the sub-directory is always called 'Raw' or 'Base' ?