title: CakePHP 1.3 contain not building associations correctly
body: <p>this is my first question here.  I'm having an issue with containable behavior in cakephp 1.3.  The issue is as follows:  I have a Deliverable model with the following associations:</p>
  
  <pre><code>class Deliverable extends AppModel {
    var $name = 'Deliverable';
    var $displayField = 'name';
    var $actsAs = array('Containable');
  
    var $belongsTo = array(
      'Asset' =&gt; array(
          'className' =&gt; 'Asset',
          'foreignKey' =&gt; 'asset_id',
          'dependent' =&gt; false
      ),
      'DelRouteName' =&gt; array(
          'className' =&gt; 'DelRouteName',
          'foreignKey' =&gt; 'del_route_name_id',
      ),
      'AccessGroup' =&gt; array(
          'className' =&gt; 'AccessGroup',
          'foreignKey' =&gt; false,
          'conditions' =&gt;
              'Deliverable.role_id = AccessGroup.id'
      )
  );
  
    var $hasOne = array(
      'Artifact' =&gt; array(
          'className' =&gt; 'Artifact',
          'foreignKey' =&gt; 'deliverable_id',
          'dependent' =&gt; true,
      )
  );
  
    var $hasMany = array(
      'Delivery' =&gt; array(
          'className' =&gt; 'Delivery',
          'foreignKey' =&gt; 'deliverable_id',
          'dependent' =&gt; true,
          'order' =&gt; 'Delivery.gmt_created',
      )
  );
  </code></pre>
  
  <p>And here is the configuration of the pagination settings:</p>
  
  <pre><code>$this-&gt;paginate['Deliverable'] = array_merge($this-&gt;paginate['Deliverable'], array(
          'limit' =&gt; $this-&gt;getSysPref('items_per_page', 20),
          'conditions' =&gt; array(
              'Deliverable.role_id' =&gt; $this-&gt;myRoleSetIds(),
              'Deliverable.asset_id' =&gt; $asset['Asset']['id'],
              'Delivery.gmt_created &gt;' =&gt; $keep_time
          ),
          'order' =&gt; 'Deliverable.name',
          'contain' =&gt; array(
              'AccessGroup',
              'Delivery' =&gt; array(
                  'conditions' =&gt; array(
                      'Delivery.gmt_created &gt;' =&gt; $keep_time
                  ),
                  'limit' =&gt; 1,
                  'order' =&gt; 'Delivery.gmt_created DESC'                      
              ),
              'DelRouteName'
          )
      ));
      $deliverables = $this-&gt;paginate('Deliverable');
  </code></pre>
  
  <p>As you can see, the containable behavior is attached, the associations defined, and the associated models contained (in the pagination configure section).</p>
  
  <p>This issue I'm having is that it is able to successfully query the contained models "AccessGroup" and "DelRouteName", yet it doesn't fetch the associated "Delivery" data.  The error only shows up if I set a condition on the parent model (Deliverable) targeting the child model (Delivery), which I've done before and is perfectly legal.  I get this SQL error and as you can see the table deliveries is not joined at all, yet access_groups and del_route_names are.</p>
  
  <p>Here is the SQL that cake builds:</p>
  
  <pre><code>SELECT "Deliverable"."id" AS "Deliverable__id", "Deliverable"."name" AS 
  "Deliverable__name", "Deliverable"."artifact_name" AS "Deliverable__artifact_name", 
  "Deliverable"."type" AS "Deliverable__type", "Deliverable"."asset_id" AS 
  "Deliverable__asset_id", "Deliverable"."del_route_name_id" AS 
  "Deliverable__del_route_name_id", "Deliverable"."artifact_id" AS 
  "Deliverable__artifact_id", "Deliverable"."status" AS "Deliverable__status", 
  "Deliverable"."delivery_id" AS "Deliverable__delivery_id",                         
  "Deliverable"."deliverable_id" 
  AS "Deliverable__deliverable_id", "Deliverable"."gmt_created" AS 
  "Deliverable__gmt_created", "Deliverable"."locked" AS "Deliverable__locked", 
  "Deliverable"."frozen" AS "Deliverable__frozen", "Deliverable"."cloaked" AS 
  "Deliverable__cloaked", "Deliverable"."role_id" AS "Deliverable__role_id", 
  "DelRouteName"."id" AS "DelRouteName__id", "DelRouteName"."name" AS                     
  "DelRouteName__name", 
  "DelRouteName"."type" AS "DelRouteName__type", "AccessGroup"."id" AS "AccessGroup__id", 
  "AccessGroup"."name" AS "AccessGroup__name", "AccessGroup"."dn" AS "AccessGroup__dn", 
  "AccessGroup"."filters" AS "AccessGroup__filters", "AccessGroup"."paths" AS 
  "AccessGroup__paths" FROM "deliverables" AS "Deliverable" LEFT JOIN "del_route_names" 
  AS "DelRouteName" ON ("Deliverable"."del_route_name_id" = "DelRouteName"."id") LEFT     
  JOIN "access_groups" AS "AccessGroup" ON ("Deliverable"."role_id" = "AccessGroup"."id")      
  WHERE "Deliverable"."role_id" = ('0') AND "Deliverable"."asset_id" = '2' AND 
  "Delivery"."gmt_created" &gt; '1361391936'   ORDER BY "Deliverable"."name" ASC  LIMIT 50 
  </code></pre>
  
  <p>which gives me this error (using postgresql)</p>
  
  <pre><code>Warning (2): pg_query() [http://php.net/function.pg-query]: Query failed: ERROR:  missing FROM-clause entry for table "Delivery"
  </code></pre>
  
  <p>I'm at a loss here, so any help would be greatly appreciated. Let me know if you need more information as well.</p>