In the recipe Using callbacks in behaviors we learnt how to implement different model callbacks to perform some tasks automatically. In this recipe we will continue that process and we will learn how to automatically save data that may not be provided in a save
operation.
We will use the Twitter example we have been using in this chapter, so that when a profile is saved, its Twitter URL and its last tweet are saved when creating a new record, or when updating an existing one.
We need a working TwitterAccountBehavior
together with its controllers, models, and views. Follow the recipe Using callbacks in behaviors (there's no need to enable caching in the behavior, so you can omit the There's more section).
Add two fields to the profiles table, url
and last_tweet
, by issuing the following SQL command:
ALTER TABLE `profiles` ADD COLUMN `url` VARCHAR(255) default NULL, ADD COLUMN `last_tweet` VARCHAR(140) default NULL;