Doctrine-SQLSTATE[42S22]:未找到列:1054未知列



我收到以下错误:SQLSTATE[42S22]:找不到列:1054"字段列表"中的未知列"a1_.brand_id"

当我调用这个方法时,我得到了这个错误:

public function getBrandsWithArticles() {        
    $query = $this->_em->createQuery('SELECT b, a FROM EntitiesBrand b JOIN b.articles a');
    return $query->getResult();
}

这是我的文章实体:

<?php
namespace Entities;
use DoctrineCommonCollectionsArrayCollection;
/**
 * @Entity (repositoryClass="RepositoriesArticle")
 * @Table(name="articles") 
 * @HasLifecycleCallbacks
 */
class Article {
    /**
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;
    /** @Column(type="string", length=255) */
    private $name;
    /** @Column(type="string", length=255) */
    private $thumb;
    /** @Column(type="string", length=255) */
    private $big;
    /** @Column(type="text",nullable=true) */
    private $description;
    /** @Column(type="datetime") */
    private $created;
    /** @Column(type="datetime") */
    private $updated;
    /**
     * @ManyToOne(targetEntity="Category", inversedBy="articles", cascade={"persist"})
     * @JoinColumn(name="category_id", referencedColumnName="id")
     */
    private $category;
    /**
     * @ManyToOne(targetEntity="Brand", inversedBy="articles", cascade={"persist"})
     * @JoinColumn(name="brand_id", referencedColumnName="id")
     */
    private $brand;
    /**     
     * @OneToMany(targetEntity="ArticlesQuoteItems", mappedBy="articles")
     */
    private $items;
    /** @Column(type="string", length=1) */
    private $status;
    /** @Column(type="text",nullable=true) */
    private $tips;
    /** @Column(type="text",nullable=true) */
    private $features;
    /** @Column(type="text",nullable=true) */
    private $media;
    public function __construct() {
        $this->created = $this->updated = new DateTime("now");        
        $this->details = new ArrayCollection();
    }
    /**
     * @PreUpdate
     */
    public function updated()
    {
        $this->updated = new DateTime("now");
    }
    public function created()
    {
      $this->created = new DateTime("now");
    }  
    public function setUpdated()
    {
        $this->updated = new DateTime("now");
    }    
    public function setCreated()
    {
        $this->created = new DateTime("now");
    }
?>

以下是articles表的MySQL转储:

CREATE TABLE IF NOT EXISTS `articles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category_id` int(11) DEFAULT NULL,
`name` varchar(255) COLLATE utf8_spanish2_ci NOT NULL,
`description` longtext COLLATE utf8_spanish2_ci,
`features` longtext COLLATE utf8_spanish2_ci,
`big` varchar(255) COLLATE utf8_spanish2_ci NOT NULL,
`thumb` varchar(255) COLLATE utf8_spanish2_ci NOT NULL,
`tips` longtext COLLATE utf8_spanish2_ci,
`media` longtext COLLATE utf8_spanish2_ci,
`created` datetime NOT NULL,
`updated` datetime NOT NULL,
`status` varchar(1) COLLATE utf8_spanish2_ci NOT NULL,
`brand_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX_BFDD316812469DE2` (`category_id`),
KEY `IDX_BFDD316844F5D008` (`brand_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish2_ci AUTO_INCREMENT=24 ;

我不知道怎么了。

提前感谢。。。

我在符号环境中添加了Article类,提供了以下最低限度的Brand实现:

use DoctrineORMMapping as ORM;
class Brand {
    /**
     * @ORMId @ORMColumn(type="integer")
     * @ORMGeneratedValue(strategy="AUTO")
     */
    private $id;    
    /**
     * @ORMOneToMany(targetEntity="Article", mappedBy="brand")
     */
    private $articles;  
}

然后我在DB中添加了几个条目,并在repo方法中使用您的DQL查询获取它们:一切都很好,所以请发布您的Brand代码,以了解是否存在任何问题。

相关内容

  • 没有找到相关文章

最新更新