Updating calculated gridview field

When you call save(), by default it will call validate() automatically.

Only when the validation passes, will it actually save the data; otherwise it will simply return Like normal models, Active Record instances also enjoy the massive assignment feature.

For example, in the database you are storing customers' birthdays as UNIX timestamps (which is not a good design, though), while in most cases you would like to manipulate birthdays as strings in the format of While retrieving data in terms of Active Record objects is convenient and flexible, it is not always desirable when you have to bring back a large amount of data due to the big memory footprint.

Sometimes, you may want to pre-populate your Web form for an Active Record instance with these default values.

Instead of writing raw SQL statements, you would access Active Record attributes and call Active Record methods to access and manipulate the data stored in database tables.

For example, assume The above code is equivalent to using the following raw SQL statement for My SQL, which is less intuitive, more error prone, and may even have compatibility problems if you are using a different kind of database: In this tutorial, we will mainly describe the usage of Active Record for relational databases.

You can do so by calling the yii\db\Active Record::find By Sql() method: Do not call extra query building methods after calling find By Sql() as they will be ignored.

As aforementioned, the data brought back from the database are populated into Active Record instances, and each row of the query result corresponds to a single Active Record instance.

Leave a Reply