Skip to content

Turn OFF getMyProperty() method during DB save. #1646

Description

@nowackipawel

My entity:

<?php namespace App\Entities\Question;

use CodeIgniter\Entity;

class QuestionStatMonth extends Entity
{
	protected $qsm_que_id;
	protected $qsm_year;
	protected $qsm_month;
	protected $qsm_ok;
	protected $qsm_nok;

	protected $_options = [
		'casts'   => [
			'qsm_que_id'  	=> 'integer',
			'qsm_year' 		=> 'integer',
			'qsm_month'   	=> 'integer',
			'qsm_ok'    	=> 'integer',
			'qsm_nok'    	=> 'integer',
		],
		'dates'   => [],
		'datamap' => [],
	];

	public function setQsmYear($value)
	{
		$this->qsm_year = ($value - 2000 > 0) ? $value - 2000 : null; 
print $this->qsm_year;
	}

	public function getQsmYear()
	{
		return ! is_null($this->qsm_year) ? $this->qsm_year + 2000 : null;
	}

}

when I set my $my_entity->qsm_year = 2017 I've got printed out 17 (what is correct), but when I am trying to save it in database I've got 2017 in DB. I think we should use similar approach as is in #1373 .

I will PR in a while cuz I'd like to see if it won't break any tests.

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