Skip to content

datamap Entities not works! #2747

Description

@luispastendev

Hello!

I am trying to save an entity class in my database, but at the time of mapping my values it cannot save them in the database

after validating my data I get my entity class to save it,

$discount = new Discount();
$discount->price = $this->request->getVar('price_discount');
$discount->date_from = $this->request->getVar('date_from');
$discount->date_until = $this->request->getVar('date_until');

My entity class is like this

class Discount extends Entity{

    protected $attributes = [
        'price_discount' => null,
        'date_from' => null,
        'date_until' => null
    ];

    protected $datamap = [
        'price' => 'price_discount',
        'valid_from' => 'date_from',
        'valid_until' => 'date_until'
    ];

}

My model class allows saving those fields

    protected $table      = 'discounts';
    protected $primaryKey = 'id';
    protected $returnType = 'App\Entities\Discount';
    protected $allowedFields = [
        'price','valid_from','valid_until'
    ];

The record manages to be saved but the fields defined in the datamap variable are not saved ...
I have tried to debug the query with $this->modelDiscount->getLastQuery(); and in effect does not generate the insertion of those fields

grettings!!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions