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

Update ClosureExpressionVisitor.php #68

Open
wants to merge 1 commit into
base: 2.0.x
Choose a base branch
from

Conversation

DrSchimke
Copy link

Searching for elements within ArrayCollection using element's \DateTime attributes fails, since until now the comparison uses === instead of ==.

I would like to change the cases ::EQ and ::NEQ – is this ok?

(The matching functionality in PersistentCollection works fine, if I use EXTRA_LAZY...)

Searching for elements within ArayCollection using element's \DateTime attributes fails, since until now the comparison uses === instead of ==.
@DrSchimke
Copy link
Author

Here is an example for the problem:

$collection = new ArrayCollection();
$collection->add(['date' => new \DateTime('2015-01-01 00:00:00.000'), 'id' => 1]);
$collection->add(['date' => new \DateTime('2015-01-02 00:00:00.000'), 'id' => 2]);
var_dump($collection->matching(new Criteria(Criteria::expr()->eq('date', new \DateTime('2015-01-01 00:00:00.000'))))->toArray());

@baileylo
Copy link
Contributor

baileylo commented Dec 1, 2015

This is done by design and is documented in the Doctrine doc's, you'll need to scroll down but it says:

DateTime and Object types are compared by reference, not by value. Doctrine updates this values if the reference changes and therefore behaves as if these objects are immutable value objects.

@stof
Copy link
Member

stof commented Dec 2, 2015

@baileylo this is OK for updates, but not really for querying (DQL uses the datetime value when building queries)

@mikeSimonson
Copy link
Contributor

@stof If I understand you well, this PR should be merged right ?

@beberlei
Copy link
Member

This is not a good idea, comparing entities by reference can be a huge performance drain, because it happens recursively.

Base automatically changed from master to 2.0.x January 19, 2021 07:23
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

Successfully merging this pull request may close these issues.

5 participants