title: cakephp2 join two tables from two database
body: <p>I have developing a SAAS based site, which i have to join two tables from two DBs, say table1 from DB1 and table2 from DB2. I have to get the matching records from table1 and table 2 using join in cakephp, but it throws error as below :</p>
  
  <blockquote>
    <p>Error: SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user 'dbname'@'localhost' for table 'table_name' .</p>
  </blockquote>
  
  <p>can anyone explain me how to done this using cakephp .</p>
  
  <pre><code>class table1 extends AppModel{ 
  public $useDbConfig = 'DB1'; 
  } 
  Class table2 extends AppModel{ 
  public $useDbConfig = 'DB2'; 
  
  
  function desc(){
      $this-&gt;Store-&gt;useDbConfig = 'default';
  
      $rslted = $this-&gt;find('all',array(
          'conditions' =&gt; array('Jewel.id' =&gt;1),
          'joins' =&gt; array(
              array(
                  'alias' =&gt; 'Store',
                  'table' =&gt; 'stores',
                  'type' =&gt; 'INNER',
                  'conditions' =&gt; 'Store.id = Jewel.store_id'
              )
          )
      ));
  
      return $rslted;
  }
  }   
  </code></pre>
  
  <p>while called the desc function from controller is not working throws error:</p>
  
  <blockquote>
    <p>Base table or view not found: 1146 Table <code>'site1.site1_stores'</code> doesn't exist</p>
  </blockquote>
  
  <p>but using the hasmany or belongsto on model will working , the join query is not working in controller</p>