Yii Framework Forum: Database Question - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Database Question Rate Topic: -----

#1 User is offline   MikeG0 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 13-October 09

  Posted 13 October 2009 - 06:32 PM

I'm getting started with grasping the whole MVC paradigm and had a question about how coders deal with database schema changes. In a classic single tier app, adding new fields is almost a two step process: change the database, update a couple lines of code. But it seems with yii, you change the database, then run the yiic tool, then modify the code. But does all that old code get overwritten by yiic? What's the normal workflow ... do I keep a backup and then compare and add in the code from the old version I want to keep?

Sorry if this is a silly question, but I want to keep all my ducks in a row before I begin building my app.

Thanks in advance!
0

#2 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 13 October 2009 - 06:52 PM

No, you don't rerun the yyic tool unless you add a new table. When adding a column AR will be aware of that from the db schema.

You will typically add an input field in some form, perhaps declare an attributeLabel and probably a validation rule for the new attribute.

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#3 User is offline   MikeG0 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 13-October 09

Posted 13 October 2009 - 07:41 PM

Wow, sounds pretty flexible. The comments section and the rules(), relations(), and attributeLabels() functions of the generated models code got me a little worried (they list out available columns). Is there a checklist of places to modify when the schema changes? Or is it just the the model and view files I should worry about?


Thanks for the quick reply.
0

#4 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 13 October 2009 - 08:30 PM

View PostMikeG0, on 13 October 2009 - 07:41 PM, said:

Wow, sounds pretty flexible. The comments section and the rules(), relations(), and attributeLabels() functions of the generated models code got me a little worried (they list out available columns). Is there a checklist of places to modify when the schema changes? Or is it just the the model and view files I should worry about?


Thanks for the quick reply.


rules() is the place where you add validation rules.

attributeLabels() is only used if you want display labels other than the attribute names. It's also where you would prefer to add t() method calls for label translation.

relations() doesn't change if you just add a column to the db. If you add related tables you may want to define new relationship(s).

I forgot to mention safeAttributes() where you should add the new attribute. Thus it will be massively assigned in the controller. For the basic generated CRUD I don't see the need for changing anything in the controller.

If you add a table you will run yiic on it and get the new model, the corresponding controller with CRUD actions as well as a new directory with the CRUD views.

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users