无论如何,Doctrine只选择第一行数据

时间:2014-01-03 21:35:22

标签: php sql symfony doctrine-orm doctrine

当我想在我的表中选择Doctrine仅选择第一行数据的所有类别时,我遇到了问题。

例如:

  • 我有3个类别(id:1,2和3)。我想选择所有的 这样做的类别:$categories = $entityManager->getRepository('ReuzzeReuzzeBundle:Categories') ->findAll(); 我现在得到的是:第一个实体的3倍!

  • 我有3个类别(id:1,2和3)。我想选择类别 id为2,执行此操作:$category = $entityManager->getRepository('ReuzzeReuzzeBundle:Categories')->findOneByCategoryId(2); 然后我再次获得id = 1 ...
  • 的第一个类别

这是设置问题还是其他......?有人可以帮我这个吗?当您无法选择所有数据时,这非常烦人:/

更新: 我的实体类别类:

<?php

namespace Reuzze\ReuzzeBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Categories
 *
 * @ORM\Table(name="categories", indexes={@ORM\Index(name="fk_categories_categories1_idx", columns={"category_parentid"})})
 * @ORM\Entity
 */
class Categories
{
    /**
     * @var boolean
     *
     * @ORM\Column(name="category_id", type="boolean")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $categoryId;

    /**
     * @var string
     *
     * @ORM\Column(name="category_name", type="string", length=45, nullable=false)
     */
    private $categoryName;

    /**
     * @var string
     *
     * @ORM\Column(name="category_description", type="string", length=255, nullable=false)
     */
    private $categoryDescription;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="category_created", type="datetime", nullable=false)
     */
    private $categoryCreated;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="category_modified", type="datetime", nullable=true)
     */
    private $categoryModified;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="category_deleted", type="datetime", nullable=true)
     */
    private $categoryDeleted;

    /**
     * @var \Reuzze\ReuzzeBundle\Entity\Categories
     *
     * @ORM\ManyToOne(targetEntity="Reuzze\ReuzzeBundle\Entity\Categories")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="category_parentid", referencedColumnName="category_id")
     * })
     */
    private $categoryParentid;



    /**
     * Get categoryId
     *
     * @return boolean 
     */
    public function getCategoryId()
    {
        return $this->categoryId;
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set categoryParentid
     *
     * @param \Reuzze\ReuzzeBundle\Entity\Categories $categoryParentid
     * @return Categories
     */
    public function setCategoryParentid(\Reuzze\ReuzzeBundle\Entity\Categories $categoryParentid = null)
    {
        $this->categoryParentid = $categoryParentid;

        return $this;
    }

    /**
     * Get categoryParentid
     *
     * @return \Reuzze\ReuzzeBundle\Entity\Categories 
     */
    public function getCategoryParentid()
    {
        return $this->categoryParentid;
    }
}

1 个答案:

答案 0 :(得分:2)

看起来您的问题与您的categoryId的注释定义有关。您已将其定义为boolean。这应该是integer。这可能就是为什么你只得到id为1的类别。