Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8624101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:26:31+00:00 2026-06-12T07:26:31+00:00

I have the need of get the array representation of a Doctrine 2 Entity.

  • 0

I have the need of get the array representation of a Doctrine 2 Entity. I found this library
online, and i am using this class for this purpose:

https://github.com/borisguery/bgylibrary/blob/master/library/Bgy/Doctrine/EntitySerializer.php

The thing is that the class work well but the issue is that every attribute of the entity
that is a relation to another entity(many to one) have the value null on every field on the
resulting array.

A real example:

i have the Entity Person:

<?php

namespace Entities;

/**
* @Entity(repositoryClass=”Repositories\PersonRepository”)
*/
class Person
{

/**
 * @Id @GeneratedValue
 * @Column(type="bigint")
 * @var integer
 */
protected $id;

/**
 * @Column(type="string", length=32)
 * @var string
 */
protected $firstname;

/**
 * @Column(type="string", length=32, nullable="true")
 * @var string
 */

 /**
 * @ManyToOne(targetEntity="Gender", cascade={"detach"})
 * @JoinColumn(name="gender", referencedColumnName="id")
 */
protected $gender;

And i have one person object stored on the db with gender(id->1 and name->Male).
When i use this class to convert that person object to array, i got this result:

“id”: “1”,
“firstname”: “lh”,
“middlename”: “”,
“lastname”: “kbkjbkl”,
“dob”: {
“date”: “1982-05-25 00:00:00”,
“timezone_type”: 3,
“timezone”: “America/New_York”
},
“home_phone_number”: “8798798”,
“work_phone_number”: “987987”,
“cell_phone_number”: “987987”,
“ssn”: “98798”,
“email”: “kjhlkjlk”,
“gender”: {
“id”: null,
“name”: null
},

“race”: {
“id”: null,
“name”: null
},
“address”: {
“id”: null,
“address_line1”: null,
“address_line2”: null,
“city”: null,
“zip”: null,
“state”: null
},
“marital_status”: {
“id”: null,
“name”: null
}

Notice the highlighted gender value(has nulls). When it should have 1 and Male.

I will really appreciate any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:26:32+00:00Added an answer on June 12, 2026 at 7:26 am

    I got it. The problem is that when doctrine loads an entity from the db, the relations are not loaded unless you access it. In the point when you access one of the relations, then doctrine executes the query and grab the info. In my case all the relations have null because have never been accessed. This method of loading is called in doctrine as lazy loading.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table like this -> http://jsfiddle.net/jurisKaste/FvgeQ/ And I need to get array of
I have this string (Java 1.5): :alpha;beta:gamma;delta I need to get an array: {:alpha,
I need to get array of images that have to call from server and
I have linq request. I need get item.Title in select. how do this? var
I need to get some pictures which have a specific hashtag using PHP ?
I have an array of reflectionClasses. I need to get a reflectionObject from one
I have this link http://lazhalazha.livejournal.com/data/rss with RSS in it, what I need to get
i have PostsController controller and in this controller i need get all user list.
i have string 'rgb(255,0,0)' and need to get array of decimals. The following snippet
Hi i have a Map<Str1,Str2> and i need to get the array of str2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.