简体   繁体   中英

Symfony2 findAll from entity

The query

$apartats = $em->getRepository('MyCompanyFrontendBundle:User')->findAll();

returns me an array with the same value in all values.

The numer of objects of returned array are good, but all values are equal than the first row of the table.

Example:

id:1, name:"Peter"  
id:2, name="Sofia"  
id:3, name="David"

Returns me:

id:1, name:"Peter"  
id:1, name:"Peter"  
id:1, name:"Peter"

Why is this?

Check user entity's annotation

if it is look like this

/**
     * @var boolean $id
     *
     * @ORM\Column(name="id", type="boolean", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */

change it to

/**
         * @var integer $id
         *
         * @ORM\Column(name="id", type="integer", nullable=false)
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="IDENTITY")
         */

and also check user.orm.yml file .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM