Kiruaaa
Kiruaaa

Reputation: 301

Cakephp 4 - How to merge assoaciate tables?

Is it possible to combine assoaciate table as Union? To display it all together with conditions

$this->paginate = [
  'contain' => ['Users', 'Posts', 'Comment', 'likes'],
];
$tweets = $this->paginate($this->lists);

Something like in query builder so I can also add condition for posts and comments

$table1 = $this->tableName
  ->find()
  ->join()
  ->where()

$table2 = $this->tableName
  ->find()
  ->join()
  ->where()

$Union->Union($table1)

Upvotes: 1

Views: 75

Answers (1)

Alexandre Elshobokshy
Alexandre Elshobokshy

Reputation: 10922

Something like the following would do using unions

$table1 = $this->tableName
  ->find()
  ->join()
  ->where()

$table2 = $this->tableName
  ->find()
  ->join()
  ->where()

$table2->union($table1);

Upvotes: 1

Related Questions