使用doctrine DQL加入时出现一些错误

时间:2014-10-28 12:28:04

标签: php doctrine-orm doctrine

我是Doctrine的新手。今天我试图从两个sql表中获取一些数据来执行此操作我使用的是doctrine DQL

//        $dql = "SELECT c FROM Entities\MainCat c WHERE c.main_cat_id > 0";
          $dql = "SELECT c FROM Entities\MainCat c JOIN c.Categories m ORDER BY c.main_cat_id";
        $query = $this->doctrine->em->createQuery($dql);
        $result = $query->getResult();
        foreach ($result as $res) {
            echo sprintf("-%s\n", $res->getStatus());
        }

第一个注释的DQL语句正在运行,没有任何错误。但是只有join语句会出现一些像这样的错误

Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message 'SELECT c FROM Entities\MainCat c JOIN c.Categories m ORDER BY c.main_cat_id' in E:\xampp\htdocs\shoping\application\libraries\Doctrine\ORM\Query\QueryException.php:39 Stack trace: #0 

以及更多......

有人可以帮我这个吗?

这是我的Entites / MainCat

namespace Entities;

use Doctrine\ORM\Mapping as ORM;

/**
 * MainCat
 */
class MainCat
{
    /**
     * @var integer
     */
    private $main_cat_id;

    /**
     * @var string
     */
    private $image;

    /**
     * @var integer
     */
    private $sortorder;

    /**
     * @var integer
     */
    private $status;

    /**
     * @var \DateTime
     */
    private $date_added;

    /**
     * @var \DateTime
     */
    private $date_modified;

    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    private $categories;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->categories = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get main_cat_id
     *
     * @return integer 
     */
    public function getMainCatId()
    {
        return $this->main_cat_id;
    }

    /**
     * Set image
     *
     * @param string $image
     * @return MainCat
     */
    public function setImage($image)
    {
        $this->image = $image;

        return $this;
    }

    /**
     * Get image
     *
     * @return string 
     */
    public function getImage()
    {
        return $this->image;
    }

    /**
     * Set sortorder
     *
     * @param integer $sortorder
     * @return MainCat
     */
    public function setSortorder($sortorder)
    {
        $this->sortorder = $sortorder;

        return $this;
    }

    /**
     * Get sortorder
     *
     * @return integer 
     */
    public function getSortorder()
    {
        return $this->sortorder;
    }

    /**
     * Set status
     *
     * @param integer $status
     * @return MainCat
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return integer 
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Set date_added
     *
     * @param \DateTime $dateAdded
     * @return MainCat
     */
    public function setDateAdded($dateAdded)
    {
        $this->date_added = $dateAdded;

        return $this;
    }

    /**
     * Get date_added
     *
     * @return \DateTime 
     */
    public function getDateAdded()
    {
        return $this->date_added;
    }

    /**
     * Set date_modified
     *
     * @param \DateTime $dateModified
     * @return MainCat
     */
    public function setDateModified($dateModified)
    {
        $this->date_modified = $dateModified;

        return $this;
    }

    /**
     * Get date_modified
     *
     * @return \DateTime 
     */
    public function getDateModified()
    {
        return $this->date_modified;
    }

    /**
     * Add categories
     *
     * @param \Entities\Categories $categories
     * @return MainCat
     */
    public function addCategorie(\Entities\Categories $categories)
    {
        $this->categories[] = $categories;

        return $this;
    }

    /**
     * Remove categories
     *
     * @param \Entities\Categories $categories
     */
    public function removeCategorie(\Entities\Categories $categories)
    {
        $this->categories->removeElement($categories);
    }

    /**
     * Get categories
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getCategories()
    {
        return $this->categories;
    }
}

这是实体/类别

namespace Entities;

use Doctrine\ORM\Mapping as ORM;

/**
 * Categories
 */
class Categories
{
    /**
     * @var integer
     */
    private $cat_id;

    /**
     * @var integer
     */
    private $main_cat_id;

    /**
     * @var string
     */
    private $image;

    /**
     * @var integer
     */
    private $sortorder;

    /**
     * @var integer
     */
    private $status;

    /**
     * @var \DateTime
     */
    private $date_added;

    /**
     * @var \DateTime
     */
    private $date_modified;

    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    private $sub_cat;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->sub_cat = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get cat_id
     *
     * @return integer 
     */
    public function getCatId()
    {
        return $this->cat_id;
    }

    /**
     * Set main_cat_id
     *
     * @param integer $mainCatId
     * @return Categories
     */
    public function setMainCatId($mainCatId)
    {
        $this->main_cat_id = $mainCatId;

        return $this;
    }

    /**
     * Get main_cat_id
     *
     * @return integer 
     */
    public function getMainCatId()
    {
        return $this->main_cat_id;
    }

    /**
     * Set image
     *
     * @param string $image
     * @return Categories
     */
    public function setImage($image)
    {
        $this->image = $image;

        return $this;
    }

    /**
     * Get image
     *
     * @return string 
     */
    public function getImage()
    {
        return $this->image;
    }

    /**
     * Set sortorder
     *
     * @param integer $sortorder
     * @return Categories
     */
    public function setSortorder($sortorder)
    {
        $this->sortorder = $sortorder;

        return $this;
    }

    /**
     * Get sortorder
     *
     * @return integer 
     */
    public function getSortorder()
    {
        return $this->sortorder;
    }

    /**
     * Set status
     *
     * @param integer $status
     * @return Categories
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return integer 
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Set date_added
     *
     * @param \DateTime $dateAdded
     * @return Categories
     */
    public function setDateAdded($dateAdded)
    {
        $this->date_added = $dateAdded;

        return $this;
    }

    /**
     * Get date_added
     *
     * @return \DateTime 
     */
    public function getDateAdded()
    {
        return $this->date_added;
    }

    /**
     * Set date_modified
     *
     * @param \DateTime $dateModified
     * @return Categories
     */
    public function setDateModified($dateModified)
    {
        $this->date_modified = $dateModified;

        return $this;
    }

    /**
     * Get date_modified
     *
     * @return \DateTime 
     */
    public function getDateModified()
    {
        return $this->date_modified;
    }

    /**
     * Add sub_cat
     *
     * @param \Entities\SubCat $subCat
     * @return Categories
     */
    public function addSubCat(\Entities\SubCat $subCat)
    {
        $this->sub_cat[] = $subCat;

        return $this;
    }

    /**
     * Remove sub_cat
     *
     * @param \Entities\SubCat $subCat
     */
    public function removeSubCat(\Entities\SubCat $subCat)
    {
        $this->sub_cat->removeElement($subCat);
    }

    /**
     * Get sub_cat
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getSubCat()
    {
        return $this->sub_cat;
    }
}

在我的Mappings文件夹中我有一个像这样的Entities.MainCat.dcm.yaml文件(我觉得这个文件在加入部分时有一些错误但我不知道)

Entities\MainCat:
  type: entity
  table: main_cat
  fields:
    main_cat_id:
      type: integer
      id: true
      generator:
        strategy: AUTO
    image:
      type: string
      length: 255
      nullable: false
    sortorder:
      type: integer
      length: 3
      column: sort_order
      options:
          defauld: 0
    status:
      type: integer
      length: 1
      nullable: false
      options:
          default: 0
    date_added:
        type: datetime
        nullable : false
    date_modified:
        type: datetime
        nullable : false
  oneToMany:
      categories:
          targetEntity: Categories
          mappedBy: main_cat
          joinColumns:
            main_cat_id:
                referencedColumnName: cat_id

0 个答案:

没有答案