Neo4j-PHP-OGM
Neo4j-PHP-OGM copied to clipboard
weird array collection behaviour
i'm checking if a collection of liked venues contains a particular venue. at the time of the check the collection appears empty. i have to call the getLikedVenues() method, after that the collection is initialized and the check returns true. the venue i check for definitely belongs to the collection.
/** @OGM\ManyToMany(relation="like") */
$likedVenues
public function __construct()
{
$this->likedVenues = new Doctrine\Common\Collections\ArrayCollection;
}
public function likesVenue(Venue $venue)
{
$this->getLikedVenues(); //until i call this, the dump returns empty collection
dump($this->likedVenues);
return $this->likedVenues->contains($venue); //returns false if getLikedVenues() is not called.
}
public function getLikedVenues()
{
return $this->likedVenues;
}
this is also true for other collections, i thought this had been already resolved.
yep, the collections are not initialized. and don't get initialized when accessing them. which is weird because i think it had worked before. maybe it has to do something with the new doctrine common version.
This is based on how the proxy is implemented at this time. The loading occurs when a public call is made with a method that matches the property name.
I can think of a way around it for array collections, but it would make the behavior inconsistent with the single object. Calling the get method does not seem like a big deal.
maybe. i'm sure this works in other doctrine libraries without calling the getter.
It depends on the fetchMode as far as I can remember. I had run into issues as well with Doctrine when accessing properties directly. I verified the way doctrine proxies are generated and they are very similar. The only difference is that they seem to load everything at once while I load it per-property.