Dipak
Dipak

Reputation: 2308

Doctrine2 query with QueryBuilder returns array instead of object

I want to get doctrin2 query result in object format but it gives me in array format. I tried but I can't succeed.

This is demo query but if I want to apply similar types of join in another query than also requires results in object format but in all of them.

Can you have any solution?

return $this->createQueryBuilder("u")
->select("u.id as userid, up.id as profileid, u.username, u.email, u.isactive, up.firstname, up.lastname, up.profileimage, up.address, up.zipcode, up.biography")
->innerjoin("u.userprofile", "up")
->where("u.id = :userid")
->setParameter(":userid", $userid)
->getQuery()
->getResult();

ResultSet :

Array
(
    [userid] => 4
    [profileid] => 3
    [username] => Test user
    [email] => [email protected]
    [isactive] => 1
    [firstname] => MyFname
    [lastname] => MyLname
    [profileimage] => 5111ea998c9476c2231180050d5ad64dc3298fe0.jpeg
    [address] => My Address
    [zipcode] => 36102555
    [biography] => This is my first symfon2.3 project.
)

Upvotes: 2

Views: 2822

Answers (1)

xurshid29
xurshid29

Reputation: 4210

May be it's because you 're not loading the object fully, as you're loading it partially. That's why ORM is converting it automatically. You can use partial keyword to force it to load as partial object, but be carefull.

Upvotes: 3

Related Questions