Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Unexpected behavior of refresh() method #158

Open
cebe opened this issue Oct 13, 2017 · 0 comments
Open

Unexpected behavior of refresh() method #158

cebe opened this issue Oct 13, 2017 · 0 comments

Comments

@cebe
Copy link
Contributor

cebe commented Oct 13, 2017

When a record is loaded using the EntityManager, and afterwards some changes are made to the database without using the EntityManager, I see no way to reload the record to retrieve fresh information from the DB. I was expecting the refresh() method to do this, but it does not work. Also it seems there is no documentation about this method.

I demonstrate the problem in form of a test case using the code from OneToManyRelationshipEntityTest:

    // create initial data
    $owner = new Owner('M');
    $house1 = new House();
    $house1->setAddress('A Street 1');
    $this->persist($owner, $house1);
    $this->em->flush();
    $this->assertGraphExist('(o:Owner {name:"M"})');
    $this->assertGraphExist('(h:House {address: "A Street 1"})');
    $this->em->flush();
    $this->em->clear();

     // load owner instance
    /** @var Owner $me */
    $me = $this->em->getRepository(Owner::class)->findOneBy(['name' => 'M']);

    $this->assertSame(0, $me->getAcquisitions()->count());

    // make some changes to the db
    $this->em->getDatabaseDriver()->run('MATCH (o:Owner {name:"M"}), (h:House {address: "A Street 1"}) CREATE (o)-[r:ACQUIRED {year: 1980}]->(h)');
    $this->assertGraphExist('(o:Owner {name:"M"})-[r:ACQUIRED {year: 1980}]->(h:House {address: "A Street 1"})');

    // this line should fetch a new record, but somehow it uses a chaced one, as the assertation below fails
    $me = $this->em->getRepository(Owner::class)->findOneBy(['name' => 'M']);

    // uncommenting this line complains that the entity is not managed by the entity manager, however if it is cached, I expect it to be refreshed by this.
    //$this->em->refresh($me);
    $this->assertSame(1, $me->getAcquisitions()->count());

Any idea what I am doing wrong? Not sure if its a bug or I am missing something but at least some documentation is needed on how to properly refresh entities. Thanks!

I'll submit a PR with the failing test.

cebe added a commit to cebe/neo4j-php-ogm that referenced this issue Oct 13, 2017
expecting `refresh()` method to update the record
@cebe cebe mentioned this issue Oct 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant