Wiki

Articles tagged with "active record", sorted by ratingX
Displaying 1-10 of 17 result(s).

Searching and sorting by related model in CGridView

Created 6 years ago by Maciej LiżewskiTutorials86 comments – viewed 201,769 times – ( +126 / -1 ) – version 1.1
Lets say we have two models and relation between them:

Single table inheritance

Created 6 years ago by samdarkHow-tos8 comments – viewed 38,574 times – ( +41 / -1 ) – version 1.1
Relational databases do not support inheritance so if we need to represent it, we have to somehow store meta info while keeping performance by minimizing JOINs. One way to solve this problem is using single table inheritance. All fields for the whole class tree are stored in a single table. Class name is stored in the type field of the same table.

Accessing data in a join table with the related models

Created 6 years ago by fsbHow-tos8 comments – viewed 115,644 times – ( +28 / -2 ) – version 1.1
Sometimes the right place to store application data is in a join table. For example, movie viewers either like or don’t like the movies they watched.

1:n relations sometimes require CDbCriteria.together

Created 6 years ago by fsbTips5 comments – viewed 40,198 times – ( +16 / -1 ) – version 1.1
There are situations in which Active Record will generate nonsense queries from what a nieve Yii user might think is reasonable code. One such situation is a CActiveDataProvider using CDbCriteria to get data from parent and 1:n child table with a condition on the child table.

A simple class to use a different db for a module

Created 6 years ago by tydeas_drTips3 comments – viewed 19,599 times – ( +10 / -1 ) – version 1.1
What would you do if you want/need to have a different than the main database connection in an module's models?

Debugging CActiveRecord failed save() attempts

Created 4 years ago by BoazTips0 comments – viewed 24,039 times – ( +5 / -1 ) – version 1.1
When you're filling up a form of a CActiveRecord (using CActiveForm for example), usually you'll construct your code so that in case of validation error you'll get back the form with the error displayed back to you, typically when CActiveForm.errorSummary() is used. This is how its done by Gii.

Google style sign out of all other sessions

Created 3 years ago by Rohit SutharHow-tos2 comments – viewed 9,341 times – ( +4 / -1 ) – version 1.1
In this wiki I will show how could logout from all other sessions or all other places.

Expert's model generation with Gii

Created 3 years ago by le_topTips0 comments – viewed 9,391 times – ( +3 / -1 ) – version 1.1
Efficient coding with Yii implies efficient use of the code generator. This article shares the personalised Gii templates that were built starting from the standard templates proposed by AweGen.

Inline views, write less

Created 4 years ago by FirebreakerTips0 comments – viewed 6,942 times – ( +3 / -1 )
Sometimes writing views like

Active Record snapshotting (Model data base history)

Created 2 years ago by BizleyTutorials3 comments – viewed 8,053 times – ( +2 / -1 ) – version 1.1
One of the common tasks the web application might be required to perform, especially the app using some kind of a CMS, is to save the history of data changes. Your client for sure will want the answer to this simple question - If I mess this up or delete by accident can we bring it back? Well, DB backup is one thing and quick recovery is another - let's talk about latter one.