Wiki

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

A universal model attribute for its synthetic representation

Updated about a year ago by Alexandre RodichevskiTips2 comments – viewed 4,572 times – ( -1 ) – version 2.0
It is convenient to use the same identification attribute, say info, in all of the active records of your application. It should be a virtual read-only attribute defined by a getter method, its label being the model name.

Active Record snapshotting (Model data base history)

Updated 2 years ago by BizleyTutorials3 comments – viewed 8,054 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.

Google style sign out of all other sessions

Updated 2 years ago by Rohit SutharHow-tos2 comments – viewed 9,343 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

Updated 3 years ago by le_topTips0 comments – viewed 9,392 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.

Searching and sorting by related model in CGridView

Updated 3 years ago by Kostas Apazidis (KonApaz)Tutorials86 comments – viewed 201,777 times – ( +126 / -1 ) – version 1.1
Lets say we have two models and relation between them:

How to avoid a database update if the ActiveRecord was not modified

Updated 3 years ago by tomvdpHow-tos0 comments – viewed 12,058 times – ( +1 / -1 ) – version 1.1
The classic Yii way for doing an update action is as follows:

Debugging CActiveRecord failed save() attempts

Updated 3 years ago by BoazTips0 comments – viewed 24,040 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.

1:n relations sometimes require CDbCriteria.together

Updated 3 years ago by fsbTips5 comments – viewed 40,200 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.

Inline views, write less

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

Using sub query for doubletts

Updated 4 years ago by mbTips3 comments – viewed 14,328 times – ( +2 / -1 ) – version 1.1
find doubletts by db fields. in this example i will check doublets for 3 tabelfields (col1,col2,col3). so i will get a subquery with the condition, select and grouping of the tablefields. the having with COUNT() > 1 means: find all records more then one result.