title: how to fetch users with countries, cities, states by using containable behavior in cakephp 2.x
body: <p>I have these models : 
  <strong>Country,State,City,User</strong>
  with relations :
  <strong>Country hasMany State, 
  State hasMany City, 
  City hasMany User,</strong> </p>
  
  <p><strong>State belongsTo Country, 
  City belongsTo State, 
  User belongsTo City,</strong> </p>
  
  <p>Now I want to fetch all the users with not only their cities but also countries and states.
   How can I do this?</p>
  
  <p>Controller
  <strong>users/index</strong>:</p>
  
  <pre><code> public function index() {
  $this-&gt;User-&gt;Behaviors-&gt;load('Containable');
          $this-&gt;paginate = array('contain'=&gt;array('State'));
          debug($this-&gt;Paginator-&gt;paginate());exit;
          $this-&gt;set('users', $this-&gt;Paginator-&gt;paginate());
      }
  </code></pre>
  
  <p><strong>output</strong> : </p>
  
  <pre><code>    Warning (512): Model "User" is not associated with model "State" [CORE\Cake\Model\Behavior\ContainableBehavior.php, line 342]
  
  \app\Controller\UsersController.php (line 27)
  
  array(
      (int) 0 =&gt; array(
          'User' =&gt; array(
              'id' =&gt; '1',
              'name' =&gt; 'username',
              'city_id' =&gt; '1'
          )
      )
  )
  </code></pre>
  
  <p>Model <strong>Country</strong> :</p>
  
  <pre><code>public $hasMany = array(
      'State' =&gt; array(
          'className' =&gt; 'State',
          'foreignKey' =&gt; 'country_id',
          'dependent' =&gt; false,
          'conditions' =&gt; '',
          'fields' =&gt; '',
          'order' =&gt; '',
          'limit' =&gt; '',
          'offset' =&gt; '',
          'exclusive' =&gt; '',
          'finderQuery' =&gt; '',
          'counterQuery' =&gt; ''
      )
  );
  </code></pre>
  
  <p>Model <strong>State</strong> :</p>
  
  <pre><code>public $belongsTo = array(
          'Country' =&gt; array(
              'className' =&gt; 'Country',
              'foreignKey' =&gt; 'country_id',
              'conditions' =&gt; '',
              'fields' =&gt; '',
              'order' =&gt; ''
          )
      );
  
      public $hasMany = array(
          'City' =&gt; array(
              'className' =&gt; 'City',
              'foreignKey' =&gt; 'state_id',
              'dependent' =&gt; false,
              'conditions' =&gt; '',
              'fields' =&gt; '',
              'order' =&gt; '',
              'limit' =&gt; '',
              'offset' =&gt; '',
              'exclusive' =&gt; '',
              'finderQuery' =&gt; '',
              'counterQuery' =&gt; ''
          )
      );
  </code></pre>
  
  <p>Model <strong>City</strong> :</p>
  
  <pre><code>public $belongsTo = array(
      'State' =&gt; array(
          'className' =&gt; 'State',
          'foreignKey' =&gt; 'state_id',
          'conditions' =&gt; '',
          'fields' =&gt; '',
          'order' =&gt; ''
      )
  );
  
  
  public $hasMany = array(
      'User' =&gt; array(
          'className' =&gt; 'User',
          'foreignKey' =&gt; 'city_id',
          'dependent' =&gt; false,
          'conditions' =&gt; '',
          'fields' =&gt; '',
          'order' =&gt; '',
          'limit' =&gt; '',
          'offset' =&gt; '',
          'exclusive' =&gt; '',
          'finderQuery' =&gt; '',
          'counterQuery' =&gt; ''
      )
  );
  </code></pre>
  
  <p>Model <strong>User</strong> : </p>
  
  <pre><code>public $belongsTo = array(
      'City' =&gt; array(
          'className' =&gt; 'City',
          'foreignKey' =&gt; 'city_id',
          'conditions' =&gt; '',
          'fields' =&gt; '',
          'order' =&gt; ''
      )
  );
  </code></pre>