I managed to have some progress. There was an overriden columnMap()
that was ignoring protected attributes. After fixing the columnMap Phalcon managed to set the protected attributes with their database values. However, setters are still not being evoked.
My Model
class User extends Model{
public $id;
protected $name;
public function setName($name){
$this->name = 'Foo '.$name.' bar';
}
public function getName(){
return $this->name;
}
}
ColumnMap
array ( 'id' => 'id', 'name' => 'name')
Tests
Model::setup([
'ignoreUnknownColumns' => true,
'disableAssignSetters' => false
]);
$user = User::findFirstById(1); // {id:1, name:'John'}
$user->getName(); // 'John'
Model::setup([
'ignoreUnknownColumns' => false,
'disableAssignSetters' => true
]);
$user = User::findFirstById(1); // {id:1, name:'John'}
$user->getName(); // 'John'
Model::setup([
'ignoreUnknownColumns' => true,
'disableAssignSetters' => true
]);
$user = User::findFirstById(1); // {id:1, name:'John'}
$user->getName(); // 'John'
Model::setup([
'ignoreUnknownColumns' => false,
'disableAssignSetters' => false
]);
$user = User::findFirstById(1); // {id:1, name:'John'}
$user->getName(); // 'John'
to populate from db to model Phalcon use assign()
method maybe some options like ignore_unknown_columns
or disable_assign_setters
are wrong