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

[BUG]: Models\MetaData uses different keys for metaData and columnMap #16393

Closed
rudiservo opened this issue Aug 6, 2023 · 2 comments
Closed
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: low Low

Comments

@rudiservo
Copy link
Contributor

Don't know if it is really a bug or intentional, Models\MetaData uses different key logic to initialize the metaData and columnMap for a given model.

ColumnMap uses get_class_lower(model) has key, while metaData uses get_class_lower(model) . "-" . schema . source
leading different entries and key names for the same model.

I find this inconsistent for 2 reasons:

  1. the getSource and getSchema are tied to the ::class in the ModelsManager, I do not see any advantage in having this in the key
  2. initialize function is used for both columnMap and metaData arrays with different conditions, maybe they should be separated in to two different functions since fetching either of them comes is already separated into different functions.

Metadata::initialize function does not use the two last parameters in the function (table and schema).

One of the tests (ReadMetadataCest) expects getAttributes to fetch metaData and columnMap from a CacheAdapter while getAttributes only returns metaDataIndex.

To Reproduce

<?php
$invoice = Invoice::findFirst();
$metadata = $invoice->getModelsMetaData()

/**
 * no direct way to retrieve metadata
 */
var_dump($metadata);

Expected behavior
The same key entry for MetaData::metaData and MetaData::columnMap
getAttributes should only expect to retrieve and write to cache adapter MetaData has it is the only thing it returns.

Details

  • Phalcon version: 5.2.3
  • PHP Version: 8.2
  • Operating System: docker
  • Installation type: pecl
@rudiservo rudiservo added bug A bug report status: unverified Unverified labels Aug 6, 2023
@rudiservo
Copy link
Contributor Author

I have looked more into the matter, every time getAttributes() is called, getColumnMap() is also called either before or after.
By that logic the behaviour should be clear separation of logic between columpMap initialize and metadata initialize.

MetaData is InjectionAware, not initializeAware so there is no conflict.

@rudiservo
Copy link
Contributor Author

merged

@niden niden added status: low Low 5.0 The issues we want to solve in the 5.0 release and removed status: unverified Unverified labels Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: low Low
Projects
Status: Released
Development

No branches or pull requests

2 participants