这个问题多次被问到不同的数据和不同的方式,但我看不出我做错了什么
我正在尝试查询ArticleFamily并获取属于特定语言的条目。
$qb = $this->em->createQueryBuilder();
$qb->select('af', 'afl')
->from('DatabaseBundle:ArticleFamily', 'af')
->leftJoin('af.articleFamilyLanguages', 'afl')
->where('afl.language = :languageId')
->setParameter('languageId', 3);
此查询返回错误Notice: Undefined index: language
所以我猜它与地图有关,但我看不出错误在哪里
ArticleFamily实体
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="article_name_key", type="string", length=50, nullable=false)
*/
private $articleNameKey;
/**
* @var string
*
* @ORM\Column(name="short_key", type="string", length=5, nullable=false)
*/
private $shortKey;
/**
* @var boolean
*
* @ORM\Column(name="asset_synced", type="boolean", nullable=false)
*/
private $assetSynced;
/**
* @var \Doctrine\Common\Collections\Collection|Article[]
*
* @ORM\OneToMany(
* targetEntity="DatabaseBundle\Entity\Article",
* mappedBy="articleFamily",
* cascade={"all"},
* orphanRemoval=true)
* @ORM\OrderBy({"articleId" = "ASC"})
*/
private $relatedArticles;
/**
* @var \Doctrine\Common\Collections\Collection|Article[]
*
* @ORM\OneToMany(
* targetEntity="DatabaseBundle\Entity\Asset",
* mappedBy="articleFamily",
* cascade={"all"},
* orphanRemoval=true)
*/
private $relatedAssets;
/**
* @var \Doctrine\Common\Collections\Collection|ArticleFamilyLanguage[]
*
* @ORM\OneToMany(
* targetEntity="DatabaseBundle\Entity\ArticleFamilyLanguage",
* mappedBy="articleFamily",
* cascade={"all"},
* orphanRemoval=true)
* @ORM\OrderBy({"language" = "ASC"})
*/
private $articleFamilyLanguages;
/**
* @var \Doctrine\Common\Collections\Collection|ArticleFamilyInCategory[]
*
* @ORM\OneToMany(
* targetEntity="DatabaseBundle\Entity\ArticleFamilyInCategory",
* mappedBy="articleFamily",
* cascade={"all"},
* orphanRemoval=true)
*/
private $articleFamilyInCategories;
/**
* Constructor
*/
public function __construct()
{
$this->relatedArticles = new \Doctrine\Common\Collections\ArrayCollection();
$this->relatedAssets = new \Doctrine\Common\Collections\ArrayCollection();
$this->articleFamilyLanguages = new \Doctrine\Common\Collections\ArrayCollection();
$this->articleFamilyInCategories = new \Doctrine\Common\Collections\ArrayCollection();
}
ArticleFamilyLanguage实体
/**
* @var string
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=50, nullable=true)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="seo_description", type="string", length=156, nullable=true)
*/
private $seoDescription;
/**
* @var string
*
* @ORM\Column(name="seo_keywords", type="string", length=255, nullable=true)
*/
private $seoKeywords;
/**
* @var string
*
* @ORM\Column(name="seo_title", type="string", length=56, nullable=true)
*/
private $seoTitle;
/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @var string
*
* @ORM\Column(name="description_important", type="text", nullable=true)
*/
private $descriptionImportant;
/**
* @var string
*
* @ORM\Column(name="description_info", type="text", nullable=true)
*/
private $descriptionInfo;
/**
* @var string
*
* @ORM\Column(name="description_info_visible", type="text", nullable=true)
*/
private $descriptionInfoVisible;
/**
* @var string
*
* @ORM\Column(name="description_discount", type="text", nullable=true)
*/
private $descriptionDiscount;
/**
* @var string
*
* @ORM\Column(name="thesaurus", type="text", nullable=true)
*/
private $thesaurus;
/**
* @var string
*
* @ORM\Column(name="important_feature", type="string", length=128, nullable=true)
*/
private $importantFeature;
/**
* @var Language
*
* @ORM\ManyToOne(targetEntity="DatabaseBundle\Entity\Language")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="language_id", referencedColumnName="id")
* })
*/
protected $language;
/**
* @var ArticleFamily
*
* @ORM\ManyToOne(targetEntity="DatabaseBundle\Entity\ArticleFamily", inversedBy="articleFamilyLanguages")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="article_family_id", referencedColumnName="id")
* })
*/
private $articleFamily;
语言实体
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="iso2", type="string", length=2, nullable=true)
*/
private $iso2;
/**
* @var string
*
* @ORM\Column(name="nav_code", type="string", length=3, nullable=true)
*/
private $navCode;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=50, nullable=true)
*/
private $name;
/**
* @var boolean
*
* @ORM\Column(name="active", type="boolean", nullable=true)
*/
private $active;
答案 0 :(得分:1)
有一件事是您在where子句中提供外键id值而不是Language对象。您可以尝试使用IDENTITY功能(例如 - > where(' IDENTITY(afl.language)=:languageId'))http://doctrine-orm.readthedocs.org/en/latest/reference/dql-doctrine-query-language.html#dql-functions