Computed attributes odd behavior

memesaregood5 days ago

I have this attribute:

var checkIgnition = () -> {
    !empty(ignition) ? !ignition ? false : true : null
}

var checkRPM = () -> {
    !empty(rpm) ? rpm > 1000 ? true : false : null
}

var getHours = () -> {
    !empty(engine_hours)
    ?
        engine_hours
    :
        hours / 1000 / 60 / 60
}

var getLastHours = () -> {
    !empty(lastEngine_hours)
    ?
        lastEngine_hours
    :
        lastHours / 1000 / 60 / 60
}

var validator = () -> { 
true
}


validator() 
? 
    empty(lastWorkHours) 
    ? 
        1
    : 
        empty(hours)
        ?
            3
        :
            4
: 
    empty(lastWorkHours) 
    ? 
        0 
    : 
        lastWorkHours

For some reason, the attributes engine does not realize that 'hours' attribute is present in the position, and the result of the computation is always 3. But when the attribute is tested via the test feature, the result is 4. What could be wrong? Could this be somehow related to the priority of the computed attribute?

Anton Tananaev5 days ago

Probably because hours are calculated after computed attributes.

memesaregood5 days ago

Is there a way to calculate hours before the attributes? Can you please pinpoint a place in the codebase that calculates the hours?

Anton Tananaev5 days ago
memesaregood4 days ago

Thanks. Swapped the lines, works like a charm now.