我收到此错误:SQLSTATE[42S22]: Column not found: 1054 Unknown column 'a1_.brand_id' in 'field list'
调用此方法时出现此错误:
public function getBrandsWithArticles() {
$query = $this->_em->createQuery('SELECT b, a FROM Entities\Brand b JOIN b.articles a');
return $query->getResult();
}
这是我的文章实体:
<?php
namespace Entities;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity (repositoryClass="Repositories\Article")
* @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");
}
?>
这是文章表的 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 ;
我不知道怎么了。
提前致谢...