title: Forms with related models
body: <p>I'm facing a problem with a site I'm building using the Yii framework. </p>
  
  <p>In the site I have a form for the Photos model. The Photos model is related to the Stores model like so:</p>
  
  <p><strong>Stores Model</strong></p>
  
  <pre><code>public function relations()
  {
  return array(
  'photos' =&gt; array(self::HAS_MANY, 'Photo', 'storeId'),
  ...
  </code></pre>
  
  <p><strong>Photos Model</strong></p>
  
  <pre><code>public function relations()
  {
  return array(
  'store' =&gt; array(self::BELONGS_TO, 'Store', 'storeId'),
  );
  }
  </code></pre>
  
  <p>In the Photos form, I am trying to get a dropdown with the list of all the stores like so:</p>
  
  <pre><code>&lt;div class="row"&gt;
  &lt;?php echo $form-&gt;labelEx($model,'storeId'); ?&gt;
  &lt;?php 
  //The below line is causing the problem
  echo $form-&gt;dropDownList($model,'storeId', 
  CHtml::listData(Store::model()-&gt;findAll(), 'id', 'name')); 
  ?&gt;
  &lt;?php echo $form-&gt;error($model,'storeId'); ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>What's happening is that the page rendering breaks down at the dropdownList line. If I remove the line, the form displays properly. I have a feeling this might be because the store model's relationship with the photo model, but can't quite figure out why, or how to fix this.</p>
  
  <p>Can somebody shed some light on what could be happening? Thanks! </p>
  
  <p>Edit:</p>
  
  <p>Figured it out partly!</p>
  
  <p>I temporarily fixed the issue by adding the following code:</p>
  
  <pre><code>$criteria = new CDbCriteria();
  $criteria-&gt;limit = 10;
  $stores = Store::model()-&gt;findAll($criteria);
  </code></pre>
  
  <p>It seems the problem is that the Store table has too many records (more than 35000), which is causing some problems. Maybe this is a memory issue?</p>