主要实体Conferimenti.php
/**
* Conferimenti
*
* @ORM\Table(name="conferimenti")
* @ORM\Entity(repositoryClass="App\Repository\ConferimentiRepository")
*/
class Conferimenti
{
/**
* @var int
*
* @ORM\Column(name="id", type="bigint", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="conferimenti_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Infocomune")
* @ORM\JoinColumn(name="idcomune", referencedColumnName="id")
*/
private $idcomune;
/**
* @ORM\ManyToOne(targetEntity="Inforifiuti")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="tiporifiuto", referencedColumnName="codicerifiuto"),
* @ORM\JoinColumn(name="idcomune", referencedColumnName="idcomune")
* })
*/
private $tiporifiuto;
Inforifiuti.php
/**
* Inforifiuti
*
* @ORM\Table(name="inforifiuti")
* @ORM\Entity
*/
class Inforifiuti
{
/**
* @var int
*
* @ORM\Column(name="codicerifiuto", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
*/
private $codicerifiuto;
/**
* @var int
*
* @ORM\Column(name="idcomune", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
*/
private $idcomune;
/**
* @var string
*
* @ORM\Column(name="descrizione", type="string", length=80, nullable=false)
*/
private $descrizione;
Infocomune.php
/**
* Infocomune
*
* @ORM\Table(name="infocomune")
* @ORM\Entity
*/
class Infocomune
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="infocomune_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="nome", type="string", length=80, nullable=false)
*/
private $nome;
[我正在尝试执行此查询(在Postgres上运行),但无法与ORM一起使用:(
SELECT r.descrizione, SUM(c.peso) as totale
INNER JOIN inforifiuti AS r ON r.codicerifiuto = c.tiporifiuto AND r.idcomune = c.idcomune
WHERE c.idcomune = :id_comune AND c.dataora >= '2019-01-01' AND c.dataora <= '2019-10-30'
GROUP BY c.tiporifiuto, r.descrizione
Querybuilder
$query = $qb
->select(array('r.descrizione','SUM(c.peso) as totale'))
->innerJoin('c.tiporifiuto','r', Expr\Join::WITH, $qb->expr()->andX(
$qb->expr()->eq('c.tiporifiuto', 'r.codicerifiuto'),
$qb->expr()->eq('c.idcomune', 'r.idcomune')
))
->where('c.idcomune = :id_comune')
->andWhere($qb->expr()->between('c.dataora', ':date_from', ':date_to'))
->setParameter('id_comune', $id_comune)
->setParameter('date_from', $date_from, \Doctrine\DBAL\Types\Type::DATETIME)
->setParameter('date_to', $date_to, \Doctrine\DBAL\Types\Type::DATETIME)
->groupBy('c.tiporifiuto')
->addGroupBy('r.descrizione')
->getQuery();
我收到此错误
不支持具有复合主键的实体的单值关联路径表达式。在查询中明确命名组合主键的组件。
试图用相同的错误替换-> GroupBy
->add('groupBy', new Expr\GroupBy(['c.tiporifiuto', 'r.descrizione']))
UPDATE尝试使用直接DQL,但相同的相同错误
$query = $this->getEntityManager()->createQuery(
'SELECT r.descrizione, SUM(c.peso) as totale
FROM App\Entity\conferimenti AS c
INNER JOIN App\Entity\inforifiuti AS r
WHERE c.idcomune = :id_comune AND c.dataora >= :date_from AND c.dataora <= :date_to
GROUP BY c.tiporifiuto, r.descrizione')
->setParameter('id_comune', $id_comune)
->setParameter('date_from', $date_from, \Doctrine\DBAL\Types\Type::DATETIME)
->setParameter('date_to', $date_to, \Doctrine\DBAL\Types\Type::DATETIME);
不支持具有复合主键的实体的单值关联路径表达式。在查询中明确命名组合主键的组件。
尝试一下:$ this-> manager-> createQuery('SELECT .........');
像这个例子:
$query = $entityManager->createQuery(
'SELECT p
FROM AppBundle:Product p
WHERE p.price > :price
ORDER BY p.price ASC'
)->setParameter('price', 19.99);
• Django 使用 validate_unique() 和 save() 以及复合主键插入 mySQL 数据库
• Symfony Doctrine SQLSTATE 42S02 Base Table or View not found
• Doctrine FindBy DateTime 无限过程
• 无法通过带有 java 客户端连接器的命名管道连接到 MariaDB
• 如何使用 jq [重复]读取 bash 变量中带连字符的键的 json 值
• 如何使用 Snowflake 数据创建 Grafana 仪表盘
• 使用 PdfSharpCore 合并 PDF 时链接不起作用
• 尝试连接 ESP32 和 ESP8266 时 ECONNABORTED
• 尽管使用 EAGER 加载,但多对多关系的 Doctrine n+1 问题
• 带有 MSSQL Debezium 连接器的 AWS MSK Connect 因断开连接而失败
• Insert into table with "where" clause in the mapping
• 复合键保存记录