Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refresh does not reload scopes #220

Open
davidAtInleague opened this issue May 12, 2023 · 0 comments
Open

refresh does not reload scopes #220

davidAtInleague opened this issue May 12, 2023 · 0 comments

Comments

@davidAtInleague
Copy link
Contributor

davidAtInleague commented May 12, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant