2012-08-22 87 views
1

我得到這個錯誤:SQLSTATE [42S22]:列未找到:1054未知列在 '字段列表'主義 - SQLSTATE [42S22]:列未找到:1054未知列

'a1_.brand_id'我得到這個錯誤,當我調用這個方法:

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 ; 

我不知道什麼是錯的。

在此先感謝...

+0

你從哪裏得到這樣的錯誤?調用存儲庫方法時?添加品牌實體後,您是否更新過模式? – moonwave99

+0

@DiegoCaponera我得到了調用存儲庫方法的錯誤。架構是同步的,我仔細檢查。我只是將庫方法添加到我的文章中。 –

回答

0

我加在symfony環境,我們的Article類只是爲了它的緣故,提供以下最低Brand實現:

use Doctrine\ORM\Mapping as ORM; 

class Brand { 

    /** 
    * @ORM\Id @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id;  

    /** 
    * @ORM\OneToMany(targetEntity="Article", mappedBy="brand") 
    */ 
    private $articles; 

} 

然後我增加了幾個條目在數據庫中,我用你的DQL查詢在回購方法中提取它們:一切都很順利,所以請發佈你的Brand代碼以確定是否有任何問題存在。

相關問題