我正在使用 MySQL 数据库和 Doctrine 1.1.2。
我正在尝试使用 leftJoin 编写查询,并且我试图理解结果,因为它多次给我带来了问题。在我运行了几个不同的测试之后,它似乎几乎是断断续续的,我不相信它会这样。
下面,我将粘贴 DQL 以创建查询以及它们的输出。这四个是我在试图理解为什么有时会添加“s.id IS NULL”以及为什么有时会添加“s.id IN ('184158')”时创建的示例。如果两者都没有添加我会很好,但是有人可以向我解释为什么它在那里,也许我怎么能告诉 DQL 我不想要它?
根据我所做的一些研究,我推测它可能是关于此查询是否包含子查询的错误修复 (#1868) 的一部分。但是,由于这没有子查询,我不知道如何确定测试该问题。
这是来自于教义/lib/Doctrine/Query.php 中的错误修复 #1868 的代码
// FIX #1868: If not ID under MySQL is found to be restricted, restrict pk column for null
// (which will lead to a return of 0 items)
$limitSubquerySql = $this->_conn->quoteIdentifier($field)
. (( ! empty($subquery)) ? ' IN (' . $subquery . ')' : ' IS NULL')
. ((count($this->_sqlParts['where']) > 0) ? ' AND ' : '');
谢谢,麻烦您了。
$query = Doctrine_Query::create()
->select('s.id, p.id')
->from('Submission s')
->leftjoin('s.Products p ON s.product_id = p.id')
->where('s.id = ?',$id)
->limit(1);
echo $query->getSqlQuery() . '< br />';
$query = Doctrine_Query::create()
->select('s.id, p.id, p.field1')
->from('Submission s')
->leftjoin('s.Products p ON s.product_id = p.id')
->where('s.id = ?',$id)
->limit(1);
echo $query->getSqlQuery() . '< br />';
$query = Doctrine_Query::create()
->select('s.id, p.id, p.field1, p.field2')
->from('Submission s')
->leftjoin('s.Products p ON s.product_id = p.id')
->where('s.id = ?',$id)
->limit(1);
echo $query->getSqlQuery() . '< br />';
$query = Doctrine_Query::create()
->select('s.id, p.id, p.field1, p.field2, p.field3')
->from('Submission s')
->leftjoin('s.Products p ON s.product_id = p.id')
->where('s.id = ?',$id)
->limit(1);
echo $query->getSqlQuery() . '< br />';
**-- OUTPUT --**
**-- $id = 184158**
SELECT s.id AS s__id, p.id AS p__id
FROM submission s
LEFT JOIN products p
ON (s.prodid = p.id)
WHERE **s.id IS NULL** AND (s.id = 184158) **<-- Notice the s.id IS NULL**
SELECT s.id AS s__id, p.id AS p__id, p.field1 AS p__field1
FROM submission s
LEFT JOIN products p
ON (s.prodid = p.id)
WHERE **s.id IN ('184158')** AND (s.id = 184158) **<-- Notice the s.id IN ('184158')**
SELECT s.id AS s__id, p.id AS p__id, p.field1 AS p__field1, p.field2 AS p__field2
FROM submission s
LEFT JOIN products p
ON (s.prodid = p.id)
WHERE **s.id IS NULL** AND (s.id = 184158) **<-- Notice the s.id IS NULL**
SELECT s.id AS s__id, p.id AS p__id, p.field1 AS p__field1, p.field2 AS p__field2, p.field3 AS p__field3
FROM submission s
LEFT JOIN products p
ON (s.prodid = p.id)
WHERE **s.id IN ('184158')** AND (s.id = 184158) **<-- Notice the s.id IN ('184158')**