Method Model::create() does not work
To Reproduce
Steps to reproduce the behavior:
use Phalcon\Mvc\Model;
class Test extends Model
{
/**
* @var integer
*/
public $id;
/**
* @var string
*/
public $firstfield;
/**
* @var string
*/
public $secondfield;
public function initialize(): void
{
$this->setSource('test');
}
}
Provide minimal script to reproduce the issue
$test = new Test();
$result =$test->create(
[
'firstfield' => 'value',
'secondfield' => 'value1'
]
);
var_dump($test); // false
print_r($test->getMessages());
Array
(
[0] => Phalcon\Messages\Message Object
(
[code:protected] => 0
[field:protected] => firstfield
[message:protected] => firstfield is required
[type:protected] => PresenceOf
[metaData:protected] => Array
(
)
)
[1] => Phalcon\Messages\Message Object
(
[code:protected] => 0
[field:protected] => secondfield
[message:protected] => secondfield is required
[type:protected] => PresenceOf
[metaData:protected] => Array
(
)
)
)
Details
4.0.0-rc.27.3.9Ini
Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.case_insensitive_column_map => Off => Off
phalcon.orm.cast_last_insert_id_to_int => Off => Off
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.column_renaming => On => On
phalcon.orm.disable_assign_setters => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.enable_literals => On => On
phalcon.orm.events => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.exception_on_failed_metadata_save => On => On
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.not_null_validations => On => On
phalcon.orm.update_snapshot_on_save => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.warning.enable => On => On
Table desc
*************************** 1. row ***************************
Field: id
Type: int(10) unsigned
Null: NO
Key: PRI
Default: NULL
Extra: auto_increment
*************************** 2. row ***************************
Field: firstfield
Type: varchar(250)
Null: NO
Key:
Default: NULL
Extra:
*************************** 3. row ***************************
Field: secondfield
Type: varchar(250)
Null: NO
Key:
Default: NULL
Extra:
In version Phalcon 3.4.3 worked
@ekmst create() doesn't have a property to set values.
You could do
$test = new Test();
$result =$test->assign(
[
'firstfield' => 'value',
'secondfield' => 'value1'
]
);
$test->create();
In Phalcon 4 we don't allow setting properties using save and create. See: https://docs.phalcon.io/4.0/en/upgrade#models
@ruudboon
That was my fault :)
@ekmst No prob. I've updated my comment with the changelog link
Thank you for your diligence @ekmst . I would blame the Greek guy that has not updated the documentation yet :)
Most helpful comment
Thank you for your diligence @ekmst . I would blame the Greek guy that has not updated the documentation yet :)