2

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.
)

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you Xurshid, But can you give me example I try to found from google but can't understand.
->select(['partial u.{id,...}']) - something like this.. I've never tried it, as it's not recommended by ORM.. You should better load it as full object..
Thanks I have done it. Xurshid29 Can You help me my another issue which is bit more complex about custom authentication provider.
Xurshid It requires to wait 90 minutes. I really appreciate your response and answer.
@Dipakchavda The answer to your question will be very long, It's not good to post an unrelated answer to this question.. Did you look at this doc page?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.