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 8556809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:26:16+00:00 2026-06-11T15:26:16+00:00

I am working on a project that utilizes Zend Framework 1.12 integrated with doctrine

  • 0

I am working on a project that utilizes Zend Framework 1.12 integrated with doctrine 2. I am having trouble with a Bidirectional One-to-Many relation in said project.
The two entities concerning my problem are Team and Player; a team can have many players.

The Team Entity:

namespace Entities;

use Doctrine\Common\Collections\Collection,
    Doctrine\Common\Collections\ArrayCollection;

/**
 * @Entity(repositoryClass="Repositories\TeamRepository")
 * @Table(name="team")
 */
class Team extends Entity{

/**
 * @Column(type="string", length=255)
 */
protected $name;

/**
 * @OneToMany(targetEntity="Player", mappedBy="team")
 */
protected $players;

public function __construct() {
    $this->players = new ArrayCollection();
}


public function getName(){
    return $this->name;
}

public function setName($name) {
    $this->name = $name;
    return $this;
}

public function getPlayers() {
    return $this->players;
}

And the Player Entity:

namespace Entities;

/**
* @Entity(repositoryClass="Repositories\PlayerRepository")
* @Table(name="player")
*/
class Player extends Entity{

    public function __construct() {

    }

    /**
     * @Column(type="string", length=255)
     */
    protected $name;

    /**
     * @ManyToOne(targetEntity="Team", inversedBy="players")
     * @JoinColumn(name="team_id", referencedColumnName="id")
     */
    protected $team;

    public function getName(){
        return $this->name;
    }

    public function setName($name) {
        $this->name = $name;
        return $this;
    }

    public function getTeam() {
        return $this->team;
    }

    public function setTeam($team) {
        $this->team = $team;
        return $this;
    }

}

Now in my player controller for example I can retrieve a player and get the team name

$oPlayer    = $this->_em->find('Entities\Player', $player_id);
$teamname   = $oPlayer->getTeam()->getName();

This works as expected and I successfully obtain the name of the players team.
However the other way around does not work. I can not retrieve all the players given a team

$oTeam = $this->_em->find('Entities\Team', $team_id);
$oPlayers = $oTeam->getPlayers();

When I var_dump this the result looks like

object(Doctrine\ORM\PersistentCollection)#238 (9) {
  ["snapshot":"Doctrine\ORM\PersistentCollection":private]=>
  array(0) {
  }
  ["owner":"Doctrine\ORM\PersistentCollection":private]=>
  object(Entities\Team)#195 (7) {
     ...
  }

Note that a persistenCollection seems to be build, however the array is empty.
I have read the doctrine manual extensively and googled my behind off and am now at a loss.

Also the fact that there is no error message, I am having a hard time solving this problem.
Any pointers would be more than welcome.

  • 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-11T15:26:17+00:00Added an answer on June 11, 2026 at 3:26 pm

    The problem has been resolved. I have been trying to puzzle the solution together for posterity but have come to the conclusion that I no longer have the files where I now suspect the original error was located. I managed to get a working copy derived from another project. By brute force ‘diff’-ing and replacing code I traced the error of the empty array of the persistent collection, to my bootstrap and resources/doctrine.php config file, which unfortunately I do not have any longer and therefore can not confirm this. With string(4) “team” still being returned (as discussed in the comments) embarrassingly I finally found out that it was just due to a die() I put in the doctrine library file and forgot about.

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

Sidebar

Related Questions

I am working on a project that utilizes a circular div laying over images
I am working on a project that utilizes .Net API (several .Net DLLs) provided
I'm working on a project that utilizes the USB Host capabilities in Android 3.2.
I'm working on a java project that utilizes XML files in Eclipse; however, I
I am currently working on a project that utilizes the jfreechart library. I am
I have an ASP.NET WebApi project that utilizes Entity Framework 4.1. I am attempting
I am working on an Android project with a few others that utilizes the
I'm working on a Rails project that utilizes Action Mailer to send out mail
I'm currently working on a project that utilizes a proprietary PCMCIA radio card to
Im working on a very simple project in java that utilizes the Swing component

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.