Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent (unexpected) matching behavior with One:Many referenced object / scalar #133

Open
jackdpeterson opened this issue Nov 17, 2017 · 1 comment

Comments

@jackdpeterson
Copy link

        $applicableParts = $partCollection->matching(
            Criteria::create()->where(Criteria::expr()->eq('partStatusType', \PartStatusType::Qualified))
        );

The above doesn't work. Below does.

$applicableParts = $partCollection->matching(
            Criteria::create()->where(Criteria::expr()->in('partStatusType', [\PartStatusType::Qualified]))
        );

This seems like odd behavior. Perhaps some documentation would be helpful because on first pass it seems like that one would be able to use the eq() expression with a referenced object. However, that throws the

    {
        return new self(sprintf(
            "Cannot match on %s::%s with a non-object value. Matching objects by id is " .
            "not compatible with matching on an in-memory collection, which compares objects by reference.",
            $class, $associationName
        ));
    }

After playing around with this, I tried out the ->in() expression which seemed to work. Any reason why all matchers couldn't be updated to support the id of the entity itself?

@lcobucci
Copy link
Member

@jackdpeterson could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing.

These tests can be used as example:

/**
* @group DDC-1637
*/
public function testMatching() : void
{
$this->fillMatchingFixture();
$col = $this->collection->matching(new Criteria(Criteria::expr()->eq('foo', 'bar')));
self::assertInstanceOf(Collection::class, $col);
self::assertNotSame($col, $this->collection);
self::assertEquals(1, count($col));
}
/**
* @group DDC-1637
*/
public function testMatchingOrdering() : void
{
$this->fillMatchingFixture();
$col = $this->collection->matching(new Criteria(null, ['foo' => 'DESC']));
self::assertInstanceOf(Collection::class, $col);
self::assertNotSame($col, $this->collection);
self::assertEquals(2, count($col));
self::assertEquals('baz', $col->first()->foo);
self::assertEquals('bar', $col->last()->foo);
}
/**
* @group DDC-1637
*/
public function testMatchingSlice() : void
{
$this->fillMatchingFixture();
$col = $this->collection->matching(new Criteria(null, null, 1, 1));
self::assertInstanceOf(Collection::class, $col);
self::assertNotSame($col, $this->collection);
self::assertEquals(1, count($col));
self::assertEquals('baz', $col[0]->foo);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants