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

No ability to query by custom mapping types #2103

Closed
petr-buchin opened this issue Nov 10, 2019 · 3 comments
Closed

No ability to query by custom mapping types #2103

petr-buchin opened this issue Nov 10, 2019 · 3 comments
Assignees
Labels
Projects
Milestone

Comments

@petr-buchin
Copy link
Contributor

petr-buchin commented Nov 10, 2019

Bug Report

Q A
BC Break no
Version 2.0.2

Summary

Currently ODM does not support querying by any PHP object values, except DateTimeInterface and ObjectId, even if there are custom mapping types to convert this values to their DB representation.
This makes using of ODM pretty weird, when you can use your value objects in your documents (entities), but you must query this documents by database values.

After a little research I found that problem is in the Type::getTypeFromPHPVariable() method, which looks unfinished:

if (is_object($variable)) {
      if ($variable instanceof DateTimeInterface) {
          return self::getType('date');
      }

      if ($variable instanceof ObjectId) {
          return self::getType('id');
      }
} else {
//...
}

Here ODM explicitly ignores any objects except DateTimeInterface and ObjectId.

I believe that maybe this behavior is a result of ODM not having an explicit way to map PHP value to custom mapping type. However, there is a mapping from field name to field type, and this info may be used to properly convert value.

Current behavior

No ability to search by PHP object values, used in custom mapping types.

How to reproduce

  1. Create custom mapping types, which converts php object to some scalar value for storing in DB.
  2. Create document, which uses this custom mapping type.
  3. Try to query by a "php value" used in custom type.
  4. Query will not find anything ever,

Expected behavior

I expect to be able to query by PHP objects, used as a type of a field in my document.

@alcaeus
Copy link
Member

alcaeus commented Nov 10, 2019

That is unfortunately known. I’ll put this on the roadmap, but can’t say when we’ll get to it.

@petr-buchin
Copy link
Contributor Author

petr-buchin commented Nov 10, 2019

@alcaeus from what I see, this is pretty straightforward to add this feature. Actually, you can see my PR, which adds this feature at least for non-array values.

For now all tests pass, except one error in the last job (with DEPLOYMENT=REPLICASET), but I believe that maybe it is not related to changes I made in this PR.

If you have any comments on that PR, I would be happy to fix it.

@alcaeus alcaeus added this to 2.1 in Roadmap Dec 17, 2019
@alcaeus
Copy link
Member

alcaeus commented May 19, 2020

Fixed in #2104.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Roadmap
2.1 (unsupported)
Development

No branches or pull requests

2 participants