Model with dropdown field in backend

I created model. It has cena_typ field and added dropdown in fields.yaml. Why doe dropdown doesn’t set on right value when i update model?

class Pojazd extends Model
{
    protected $cena_faktura_slo = ['v' => 'value 1', 'm' => 'value 2'];

    public function getCenaTypOptions()
    {
        return $this->cena_faktura_slo;
    }
}
fields.yaml

cena_typ:
  label: 'Typ'
  type: dropdown

Hi @mkinternet,

This should work:

class Pojazd extends Model
{
    // This defines the available options for the "cena_typ" dropdown field
    public function getCenaTypOptions()
    {
        return [
            'v' => 'value 1',
            'm' => 'value 2',
        ];
    }
}

Both methods getCenaTypOptions() returns same result.

@mkInternet It looks like something might be off in your setup, since this should be fairly straightforward. What value is actually being saved? Are you modifying it in any way before saving it to the database (beforeSave)? What value do you see in the database for that record?

You can access $cena_faktura_slo within Pojazd class not outside of these classe, check protected visibility