CakePHP 3 - Inner Join

0

How do I make an inner join to relate an article table to a favorite article table using cakephp 3.

favorites table:

CREATE TABLE IF NOT EXISTS 'favorites' (
'id' int(11) NOT NULL,
  'user_id' int(11) NOT NULL,
  'article_id' int(11) NOT NULL,
  'favorited' datetime NOT NULL
) 

article table:

CREATE TABLE IF NOT EXISTS 'articles' (
'id' int(11) NOT NULL,
  'name' varchar(100) NOT NULL,
  'content' text NOT NULL,
  'created' datetime NOT NULL,
  'modified' datetime NOT NULL
)
    
asked by anonymous 09.05.2015 / 18:51

1 answer

1

In CakePHP 3.x this way!

Example:

$this->Favorites
    ->find('all')
    ->leftJoin('articles', 'articles.id = Favorites.article_id');

Documentation:

leftJoin () , rightJoin () , innerJoin () and manually join ( )

    
10.05.2015 / 06:24