You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you create a model from a table that has capitalized columns, the property is saved in lower case. However, the column map exspects the field name with a leading capital letter, therefore yields "xy is required" on save().
class barcodes extends \Phalcon\Mvc\Model
{
protected$cid;
protected$aid;
protected$barcode;
publicfunctionsetCid($cid)
{
$this->cid = $cid;
return$this;
}
publicfunctionsetAid($aid)
{
$this->aid = $aid;
return$this;
}
publicfunctionsetBarcode($barcode)
{
$this->barcode = $barcode;
return$this;
}
publicfunctiongetCid()
{
return$this->cid;
}
publicfunctiongetAid()
{
return$this->aid;
}
publicfunctiongetBarcode()
{
return$this->barcode;
}
publicfunctioninitialize()
{
$this->setSource("barcodes");
$this->belongsTo('aid', '\articles', 'aid', ['alias' => 'articles']);
}
publicstaticfunctionfind($parameters = null): \Phalcon\Mvc\Model\ResultsetInterface
{
returnparent::find($parameters);
}
publicstaticfunctionfindFirst($parameters = null)
{
returnparent::findFirst($parameters);
}
publicfunctioncolumnMap()
{
return [
'cid' => 'cid',
'aid' => 'aid',
'Barcode' => 'Barcode'// leading B is capitalized, but the corresponding field is all lower case
];
}
}
When trying to save(), this yields "Barcode is required", even if set. Internally, $this->barcode gets set by setBarcode('somestring');, but the column map generated by webtools.php exspects the field to be named $this->Barcode.
Exspected behaviour
webtools.php should match the keys from the column map with the actual property names, with correct capitalization taken into account.
Details
System info and versions (if possible):
Phalcon Framework version: 4.0.6
PHP Version: 7.4.4
Operating System: Windows 10
Server: Apache
Other related info (Database, table schema): see above
The text was updated successfully, but these errors were encountered:
This is NFR.
Wont be done, because of camelize behavior, which is needed for fields named like group_id.
Changing template behavior to make Barcode be consistent breaks snake_cased fields name mutation.
As said in forums thread, ill recommend to rename fields such as Barcode to barcode or manually change columnMap() method to fulfill that needs.
Please see the discussion on the forum (https://forum.phalcon.io/discussion/20661/modelsave-saves-not-the-entire-model-return-xy-is-required) and the accepted answer (https://forum.phalcon.io/discussion/20661/modelsave-saves-not-the-entire-model-return-xy-is-required#C63301).
Actual Behavior
When you create a model from a table that has capitalized columns, the property is saved in lower case. However, the column map exspects the field name with a leading capital letter, therefore yields "xy is required" on
save()
.See this table definition:
Note the capitalized "B" of "Barcode".
The model generated by webtools.php:
When trying to
save()
, this yields "Barcode is required", even if set. Internally,$this->barcode
gets set bysetBarcode('somestring');
, but the column map generated by webtools.php exspects the field to be named$this->Barcode
.Exspected behaviour
webtools.php should match the keys from the column map with the actual property names, with correct capitalization taken into account.
Details
The text was updated successfully, but these errors were encountered: