We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Introspection Stragegy from metaData does not take into account the column map from model

If I have a model with 100 properties and I choose to map only 50, the update via $model->save() is not possible (by default) because the function doLowUpdate from model.zep checks if columnMap is array and throws an error for the unmapped columns.

I managed to change the strategy by overwriting the instrospection class with functions getMappedColumns and getMetaData to take into account only the columns from the column map (if it is declared). Is there a reason why this mod could not make it into phalcon's core?

edited Oct '19

phalcon\phalcon\mvc\model\metadata\strategy\introspection.zep:

  let defaultValues = [];
  let emptyStringValues = [];

  for column in columns {

       let fieldName = column->getName(),
           attributes[] = fieldName;

       /**
        * To mark fields as primary keys
        */

Would become:

   let defaultValues = [];
   let emptyStringValues = [];
   let columnNames = [];

     if method_exists(model, "columnMap") {
         let columnNames = array_keys(model->columnMap());
     }

   for column in columns {

       let fieldName = column->getName(),
       if count($columnNames) > 0 && !in_array(fieldName, $columnNames, true) {
             continue;
         }

           attributes[] = fieldName;

       /**
        * To mark fields as primary keys
        */