-
Notifications
You must be signed in to change notification settings - Fork 623
Description
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:
CREATE TABLE `barcodes` (
`cid` int(11) NOT NULL AUTO_INCREMENT,
`aid` int(11) NOT NULL,
`Barcode` varchar(20) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`cid`),
KEY `articleFK_idx` (`aid`),
CONSTRAINT `articleFK` FOREIGN KEY (`aid`) REFERENCES `articles` (`aid`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;Note the capitalized "B" of "Barcode".
The model generated by webtools.php:
class barcodes extends \Phalcon\Mvc\Model
{
protected $cid;
protected $aid;
protected $barcode;
public function setCid($cid)
{
$this->cid = $cid;
return $this;
}
public function setAid($aid)
{
$this->aid = $aid;
return $this;
}
public function setBarcode($barcode)
{
$this->barcode = $barcode;
return $this;
}
public function getCid()
{
return $this->cid;
}
public function getAid()
{
return $this->aid;
}
public function getBarcode()
{
return $this->barcode;
}
public function initialize()
{
$this->setSource("barcodes");
$this->belongsTo('aid', '\articles', 'aid', ['alias' => 'articles']);
}
public static function find($parameters = null): \Phalcon\Mvc\Model\ResultsetInterface
{
return parent::find($parameters);
}
public static function findFirst($parameters = null)
{
return parent::findFirst($parameters);
}
public function columnMap()
{
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
Metadata
Metadata
Assignees
Type
Projects
Status