0

Is it possible to do this in CakePHP? Can anyone give me an example how to join Comment table from db1 located on 111.111.111.111 and User table from db2 located on 222.222.222.222 where User is an owner of comment?

I'm putting my code below:

array(
  'Comment' => array('joins' => array(
     array(
       'table' => '[222.222.222.222].[db2].[User]',
       'alias' => 'UserJoin',
       'type' => 'INNER',
       'conditions' => array(
         "AND" => array('UserJoin.user_id = Comment.user_id')
       )
     )
   ), 
   'order' => array('Comment.id' => 'desc'),
   'fields' => array('UserJoin.*', 'Comment.*')
))
Oops D'oh
  • 941
  • 1
  • 15
  • 34
verdun3r
  • 71
  • 2
  • 9
  • no. You can join tables only in one database. – Jakuje Nov 02 '15 at 09:46
  • @Jakuje that's not true http://stackoverflow.com/questions/1972943/how-do-i-construct-a-cross-database-query-in-mysql But I'm not sure the Cake3 ORM supports it. – floriank Nov 02 '15 at 09:55
  • @burzum ok, but joining databases between two servers should not be possible. – Jakuje Nov 02 '15 at 09:57
  • Thanks @burzum but I'm working with Cake2 where ORM isn't available (I think). – verdun3r Nov 02 '15 at 10:02
  • @Jakuje http://dev.mysql.com/doc/refman/5.0/en/federated-storage-engine.html this works as well with the federated storage engine. verdun3r Cake2 has a ORM as well. – floriank Nov 02 '15 at 10:06

0 Answers0