Calculated field always returns 1 - atk 4.2

2019-06-04 07:09发布

问题:

I have a model that has a calculated field. The value returned is always 1. After turning the debug on, 1 is hardcoded in the query:

<?php class Model_Income extends Model_base_Income {
    function init(){
        parent::init();
        $this->debug();
        $this->addField('year')->calculated(true);
    }
    function calculate_year(){
        return '22';
    }
}

Query returned by debug

    select `name`
,(select `name` from `client` where `income`.`client_id` = `client`.`id` )
`client`,`amount`,`date`,`comment`,1 `year`,`id` 
    from `income`

I am using atk 4.2

回答1:

in 4.2 do so:

in model.

$this->add("Field_Expression", "year")->set("22");

or any sql query instead of 22.



标签: atk4