php - Better use of models and migration in symfony -
hey. i'm having hard time migrating changes i've done config/doctrine/schema.yml file.
i added column age
user
table. did php symfony doctrine:generate-migrations-diff
followed php symfony doctrine:migrate
.
looking in database, column age
added, without deleting data.
but, /lib/model/doctrine/base/baseuser.class.php not changed, there no age
field or functions age
. did command php symfony doctrine:build-model
. model updated/migrated too.
so wonder, way? seems lot of work, , i'm afraid miss each time doing it.
could go right phpmyadmin, add changes in database there , php symfony doctrine:build-schema
, , skip migration part (two commands).
also when comes use of models, right /lib/model/doctrine/user.class.php can make functions , such user "data class"? like, making function isfemale
. if not, kind of function be?
this might bad question, why model layer inside /lib/doctrine path? far have learned, keep modules inside apps, create view , controller. why should model outside. can make models without attached controller , view?
thanks.
why should model outside
because models can used everywhere in project, in example, in different applications , modules.
could go right phpmyadmin, add changes in database there , php symfony doctrine:build-schema , , skip migration part (two commands).
of course can, migrations approach track schema when deploying production or working in team.
here how use doctrine migrations (simple use-case):
- add column
age
user
model inschema.yml
./symfony doctrine:generate-migrations-diff
. migration class(-es) have been generated../symfony doctrine:migrate
. columnage
added table../symfony doctrine:build --all-classes
. build forms/filters/models
that's it. main idea doctrine:generate-migrations-diff
class:
- gathers information models' structure (php-representation of schema.yml)
- compares
schema.yml
, info (1) - generates migration classes based on difference
also when comes use of models, right /lib/model/doctrine/user.class.php can make functions , such user "data class"? like, making function isfemale . if not, kind of function be?
yes, can add such method user
model because it's users.
Comments
Post a Comment