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

[2.x] Date fields aren't converted to object #234

Closed
CauanCabral opened this issue May 16, 2020 · 6 comments
Closed

[2.x] Date fields aren't converted to object #234

CauanCabral opened this issue May 16, 2020 · 6 comments

Comments

@CauanCabral
Copy link
Contributor

When searching on tables, we have automatically conversions from database types to PHP equivalents, but on indexes, they seen always text type.

As Index can have Mapping definition, including text, boolean, numeric, timestamp, how can I teach Index / Document to convert these types to PHP equivalents?

@markstory
Copy link
Member

As Index can have Mapping definition, including text, boolean, numeric, timestamp, how can I teach Index / Document to convert these types to PHP equivalents?

The ORM does this by introspecting the SQL schema and then using the Type classes to cast results as they are read from the statement objects. An analogous system for elasticsearch could be added to ResultSet::current() to cast data based on the document schema.

@markstory markstory added this to the 3.x milestone May 17, 2020
@CauanCabral
Copy link
Contributor Author

CauanCabral commented May 17, 2020

Great.

I'm trying figure how exactly that works:

  1. ORM\ResultSet::current() only returns value from _current property
  2. ORM\ResultSet::_calculateColumnMap($query) seems the start point
  3. Database\Query::addDefaultTypes is called from __construct and, I think, is where I need to work

Did I miss something?

@markstory
Copy link
Member

I was referring to the ResultSet in this plugin. The methods you outlined are part of how the types are collected in the ORM. The casting happens inside of FieldTypeConverter which is used as a statement decorator by Cake\Database\Query::_decorateStatement()

CauanCabral pushed a commit to CauanCabral/elastic-search that referenced this issue May 18, 2020
@CauanCabral
Copy link
Contributor Author

@markstory I did a prototype based on 2.x branch (my env have Cake 3.x + elasticsearch 6.x).

Tried to be simple as possible, so, I included a Dummy driver who do nothing, justo to pass as a Type::toPHP parameter. For my current env/data, worked fine.

Thinking how to tests that before opening a PR.

Any chance to apply this on both Cake\ElasticSearch active branch (3.x and 2.x)?

CauanCabral pushed a commit to CauanCabral/elastic-search that referenced this issue May 22, 2020
CauanCabral pushed a commit to CauanCabral/elastic-search that referenced this issue May 22, 2020
CauanCabral pushed a commit to CauanCabral/elastic-search that referenced this issue May 22, 2020
CauanCabral pushed a commit to CauanCabral/elastic-search that referenced this issue May 27, 2020
Implement a basic type conversion support as in cakephp#234
Updated unit tests
Move exception to the same path as master branch
CauanCabral pushed a commit to CauanCabral/elastic-search that referenced this issue May 27, 2020
Implement a basic type conversion support as in cakephp#234
Updated unit tests
Move exception to the same path as master branch
CauanCabral pushed a commit to CauanCabral/elastic-search that referenced this issue Jun 7, 2020
Implement a basic type conversion support as in cakephp#234
Updated unit tests
Move exception to the same path as master branch
Include some tests to esLogger config
@github-actions
Copy link

This issue is stale because it has been open for 120 days with no activity. Remove the stale label or comment or this will be closed in 15 days

@github-actions github-actions bot added the stale label Sep 16, 2020
@CauanCabral
Copy link
Contributor Author

I hadn't time to finish the PR yet, but I will.

@github-actions github-actions bot closed this as completed Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants