如何在 cakephp 3.6 中 select 来自一个 table 的所有记录和来自另一个 table 的一些记录
how to select all records from one table and some from another table in cakephp 3.6
SELECT 我的Table.*, otherTable.foo, otherTable.bar...
how can we write above query in cakephp ? I tried this but didn't work.
$data = $this->Articles->find()->select(['Articles.*','Categories.name'])->innerJoineWith('Categories');
它在 SELECT Fees.* AS
Fees__*.
附近给我错误
因此,我必须写文章的所有专栏 Table。
$data = $this->Articles->find()->select(['Articles.id','Articles.name','Articles.title','Articles.description','Categories.name'])->innerJoineWith('Categories');
cakephp有解决办法吗?请告诉我。谢谢。
你可以这样做:
$this->Articles->find('all')->contain(['Categories' => function($q) {
return $q->select('Categories.name');
}])->select($this->Articles);
$this->Articles
in select statement will fetch all the records from
the Articles table and $q->select('Categories.name')
will fetch only
Category name from the associated Categories table.
$data = $this->Articles->find()
->select($this->Articles)
->select(['Categories.name'])
->innerJoineWith('Categories');
SELECT 我的Table.*, otherTable.foo, otherTable.bar...
how can we write above query in cakephp ? I tried this but didn't work.
$data = $this->Articles->find()->select(['Articles.*','Categories.name'])->innerJoineWith('Categories');
它在 SELECT Fees.* AS
Fees__*.
因此,我必须写文章的所有专栏 Table。
$data = $this->Articles->find()->select(['Articles.id','Articles.name','Articles.title','Articles.description','Categories.name'])->innerJoineWith('Categories');
cakephp有解决办法吗?请告诉我。谢谢。
你可以这样做:
$this->Articles->find('all')->contain(['Categories' => function($q) {
return $q->select('Categories.name');
}])->select($this->Articles);
$this->Articles
in select statement will fetch all the records from the Articles table and$q->select('Categories.name')
will fetch only Category name from the associated Categories table.
$data = $this->Articles->find()
->select($this->Articles)
->select(['Categories.name'])
->innerJoineWith('Categories');