I am new to the Yii framework and need some help regarding the best approach to handle a probably common problem.
In general terms, this is where I am stuck: an application shows editable data to the user that is not directly related to 1 database table. The data comes from multiple tables and, depending on the user input, one or more updates in different tables are necessary. Let us say the application also needs to update a status somewhere in some table and even add a record in yet another table. So we have simple input, but complex database updates and inserts.
What is the Yii approach for this ? Create an ActiveRecord model for every table that is involved in the updates/inserts, build the view based on the multiple models and then call save methods on all these models ? How do you get the dependencies correct: e.g. the newly created id of one record has to be used in the update in some other table. Can all this be done in a transaction so that if one fails all actions fail ?
For such cases, would it be a good solution to extend the CFormModel and add load & save methods to it ? I.e. build an “ActiveRecord light”: the extended CFormModel has all the benefits of validation rules and is extended so it can interact with the database. All specific business rules about loading/saving would be encapsulated in the load/save methods and would be written as a sequence of dbCommands with the model’s attributes available for the SQL parameters.
Am I right that the tight coupling of AR with a database table makes AR unfit for multi-table inserts/updates ? Is extending CFormModel the right path ? Or am I re-inventing the wheel here ?
Also, I am good in SQL and would want to use that skill. Leaving it to AR seems a waste.
Please guide this lost soul to the correct Yii-path!