Skip to content

refresh does not reload scopes #220

Description

@davidAtInleague
component table="RMME_A" extends="quick.models.BaseEntity" accessors=true {
    property name="id_a" type="numeric" sqltype="int";
    property name="v" type="string" sqltype="varchar";
    
    variables._key = "id_a";
    function keyType() {
		return variables._wirebox.getInstance( "NullKeyType@quick" ); // the key comes from Stripe and is not generated locally
	}

    function scopeWithComputedValue( qb ) {
        qb.appendVirtualAttribute( "computedValue" )
        qb.selectRaw("'the value in the [v] column is: <<<' + [v] + '>>>' as computedValue")
    }
}
///////
queryExecute("
	drop table if exists rmme_a;
	create table rmme_a(id_a int, v varchar(max));
")

getInstance("RMME_A").create({id_a:1, v: "AAA"})

x = getInstance("RMME_A").whereID_A(1).withComputedValue().firstOrFail()
writedump(x.getComputedValue()) // "the value in the [v] column is: <<<AAA>>>"
x.update({v: "BBB"})
x = x.refresh()
writedump(x.getV()) // "BBB", ok
writedump(x.getComputedValue()) // "the value in the [v] column is: <<<AAA>>>", computed value out of sync with actual value after a refresh


x = getInstance("RMME_A").whereID_A(1).withComputedValue().firstOrFail()
writedump(x.getComputedValue()) // "the value in the [v] column is: <<<BBB>>>", ok after full firstOrFail reload

abort;

This can lead to entities winding up in inconsistent states, where computed values from scopes are no longer in sync with actually refreshed data.

This behavior appears unchanged from Quick4, maybe it just needs to be documented.

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