【问题标题】:Doctrine 2: Entity has no field or association named x原则 2:实体没有名为 x 的字段或关联
【发布时间】:2013-04-24 08:26:51
【问题描述】:

我在使用教义做一个简单的 DQL 请求时遇到了一些麻烦。 在我的代码中找不到任何错误,所以我在这里问我的问题。

这是我尝试执行的 dcotrine 查询:

$em->createQueryBuilder()->select('p')
  ->from('\lib\models\HarvestPage', 'p')
  ->where('(p.start_hp + ?1 <= p.end_hp OR p.end_hp = 0) AND p.label_hp NOT IN (SELECT r.label_hp FROM \lib\models\HarvestRequest r)')
  ->setMaxResults(1)
  ->setParameter(1, $nbPages)
  ->getQuery()
  ->useResultCache(false)
  ->getOneOrNullResult();

它抛出了这个异常:

[Semantical Error] line 0, col 49 near 'start_hp + ?1': Error: Class lib\models\HarvestPage has no field or association named start_hp

最后是 HarvestPage 实体:

namespace lib\models;

/**
 * @Entity
 * @Table(name="harvest_page")
 */ 
class HarvestPage {
    /** @Id @Column(type="string", length=25) */
    private $label_hp;
    /** @Column(type="string", length=200, nullable=false) */
    private $link_hp;
    /** @Colum(type="smallint", nullable=false) */
    private $start_hp;
    /** @Colum(type="smallint", nullable=false) */
    private $end_hp;
}

“harvest_page”表已正确创建和填充。 我尝试了一些修复但没有成功:

  • 停用缓存
  • 尝试重命名字段

我该如何解决这个问题?

【问题讨论】:

    标签: php exception doctrine-orm associations dql


    【解决方案1】:

    元数据有@Colum,应该是@Column

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多