Doctrine ORM semantical query error: Class has no association
Doctrine ORM semantical query error: Class has no association
有点抽象的错误,存储库和实体关系映射似乎是正确的:
[Semantical Error] line 0, col 102 near 'v WHERE t.domainName': Error:
Class AppBundle\Entity\DocumentVersion has no association named document_versions
Document
实体:
/**
* @var Collection|DocumentVersion[]
*
* @ORM\OneToMany(targetEntity=DocumentVersion::class, mappedBy="document")
**/
private $document_versions;
DocumentVersion
实体:
/**
* @var Document
*
* @ORM\ManyToOne(targetEntity=\AppBundle\Entity\Document::class, inversedBy="document_versions")
* @JoinColumn(name="document_id", referencedColumnName="id")
**/
private $document;
一切似乎都被正确定义了。是什么导致了这个错误?
同一个错误的其他答案提供了不适用于我的情况的关系配置解决方案。相反,在检查 app.repository.document_version
定义是否正确后:
app.repository.document_version:
class: AppBundle\Repository\DocumentVersionRepository
factory: ['@doctrine', getRepository]
arguments: ['AppBundle\Entity\DocumentVersion']
原来是DocumentVersion
实体class中repository关系的配置:
/**
* DocumentVersion
*
* @ORM\Table(name="document_version")
* @ORM\Entity(repositoryClass="AppBundle\Repository\DocumentRepository")
* @ORM\HasLifecycleCallbacks
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*/
class DocumentVersion
运营线:
* @ORM\Entity(repositoryClass="AppBundle\Repository\DocumentRepository")
请注意,在上面一行中,它指向了错误的存储库。一旦更新为:
* @ORM\Entity(repositoryClass="AppBundle\Repository\DocumentVersionRepository")
这解决了问题。此外,在 Symfony(3.3) 中,它所依赖的实际 DQL 是在第二个异常中向下滚动屏幕:
SELECT d
FROM AppBundle\Entity\DocumentVersion d
INNER JOIN d.tenant t
INNER JOIN d.document_versions v
WHERE t.domainName = :domain_name
ORDER BY d.name ASC
希望这可以防止有人不必要地旋转他们的车轮。 :)
有点抽象的错误,存储库和实体关系映射似乎是正确的:
[Semantical Error] line 0, col 102 near 'v WHERE t.domainName': Error:
Class AppBundle\Entity\DocumentVersion has no association named document_versions
Document
实体:
/**
* @var Collection|DocumentVersion[]
*
* @ORM\OneToMany(targetEntity=DocumentVersion::class, mappedBy="document")
**/
private $document_versions;
DocumentVersion
实体:
/**
* @var Document
*
* @ORM\ManyToOne(targetEntity=\AppBundle\Entity\Document::class, inversedBy="document_versions")
* @JoinColumn(name="document_id", referencedColumnName="id")
**/
private $document;
一切似乎都被正确定义了。是什么导致了这个错误?
同一个错误的其他答案提供了不适用于我的情况的关系配置解决方案。相反,在检查 app.repository.document_version
定义是否正确后:
app.repository.document_version:
class: AppBundle\Repository\DocumentVersionRepository
factory: ['@doctrine', getRepository]
arguments: ['AppBundle\Entity\DocumentVersion']
原来是DocumentVersion
实体class中repository关系的配置:
/**
* DocumentVersion
*
* @ORM\Table(name="document_version")
* @ORM\Entity(repositoryClass="AppBundle\Repository\DocumentRepository")
* @ORM\HasLifecycleCallbacks
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*/
class DocumentVersion
运营线:
* @ORM\Entity(repositoryClass="AppBundle\Repository\DocumentRepository")
请注意,在上面一行中,它指向了错误的存储库。一旦更新为:
* @ORM\Entity(repositoryClass="AppBundle\Repository\DocumentVersionRepository")
这解决了问题。此外,在 Symfony(3.3) 中,它所依赖的实际 DQL 是在第二个异常中向下滚动屏幕:
SELECT d
FROM AppBundle\Entity\DocumentVersion d
INNER JOIN d.tenant t
INNER JOIN d.document_versions v
WHERE t.domainName = :domain_name
ORDER BY d.name ASC
希望这可以防止有人不必要地旋转他们的车轮。 :)