DatabaseMapper automaticly drops default parameters?

Hi,

I’ve launched my own app but noticed (after debugging a while - I’m not accustomed to PHP but learning! :grinning_face_with_smiling_eyes: ) that the Database Engine will strip away parameters if they are set as default in the Entity?

e.g. given the code with functionCall createBook(12):
final class Book extends Entity implements JsonSerializable {
protected ?int $position = 12;
public function createBook(int $position,): Book {
$book = new Book();
$book->setPosition($position);
return $this->insert($book);}

Will launch the query INSERT() - stripping away the integer 12. (Which in my case caused the system to throw an error because position is defined explicitely as not-null in the Database schema)

Is this intended?

1 Like

Hi!

This is unfortunate and quite a few people have run into this, but it’s a direct result of how Entity is designed. If you set the position to default to 12, you will need to set the database column to default to 12 as well in your migrations. Otherwise, do not set a default value for Entity properties.

2 Likes