Calculated field always returns 1 - atk 4.2

2019-06-04 07:00发布

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

标签: atk4
1条回答
祖国的老花朵
2楼-- · 2019-06-04 07:39

in 4.2 do so:

in model.

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

or any sql query instead of 22.

查看更多
登录 后发表回答