Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Very General rule from my experience with Yii and massive databases:</p> <p><strong>Use Yii Active Record when:</strong></p> <ol> <li>You want to retrieve and post single to a few rows in the database (e.g. user changing his/her settings, updating users balance, adding a vote, getting a count of users online, getting the number of posts under a topic, checking if a model exists)</li> <li>You want to rapidly design a hierarchical model structure between your tables, (e.g. $user->info->email,$user->settings->currency) allowing you to quickly adjust displayed currency/settings per use.</li> </ol> <p><strong>Stay away from Yii Active Record when:</strong></p> <ol> <li><p>You want to update several 100 records at a time. (too much overhead for the model)</p> <pre><code>Yii::app()-&gt;db-&gt;command() </code></pre> <p>allows you to avoid the heavy objects and retrieves data in simple arrays.</p></li> <li><p>You want to do advanced joins and queries that involve multiple tables.</p></li> <li><p>Any batch job!! (e.g. checking a payments table to see which customers are overdue on their payments, updating database values etc.)</p></li> </ol> <p>I love Yii Active Record, but I interchange between the Active Record Model and plain SQL (using Yii::app()->db) based on the requirement in the application.</p> <p>At the end I have the option whether I want to update a single users currency</p> <pre><code>$user-&gt;info-&gt;currency = 'USD'; $user-&gt;info-&gt;save(); </code></pre> <p>or if I want to update all users currencies:</p> <pre><code>Yii::app()-&gt;db-&gt;command('UPDATE ..... SET Currency="USD" where ...'); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload