d
quick6 q
I have a quick entity, retrieved via a relationship method, which has methods that seem in quick6 to longer be invokable via onMissingMethod. Seems like a bug but maybe it's a design thing. I have a luceedebug screenshot of the method I want to call but that quick is not calling
e
You are trying to call a method called
NO_GLOBAL_SCOPES
? Is it on
qCompetitionRegistration
?
d
that's correct, you can see from the watch that it is a thing that when invoked returns itself
but it doesn't appear to end up being invoked by onMissingMethod logic, which I think only looks for
scope*
methods now?
r
I dont think quick ever implemented a method by that name on a quick entity or the builder/qb classes. Are you sure its not a method that is supposed to be implemented in your code base?
d
yes that's our code, I maybe should have clarified that, since it looks like a methodname that quick would use. like we have
function NO_GLOBAL_SCOPES() {...}
.
r
In which class do you implement that method?
is it a base entity or something like that?
d
qCompetitionRegistration, which is the the current quickBuilder's entity
r
could you provide a snippet on how you are trying call that method?
d
Copy code
component X {
   function Y() { return hasOne(Y) }
}
component Y {
   function FOO() { ... }
}
// later
getInstance("X").firstOrFail().Y().FOO() // Method FOO does not exist on QueryBuilder (thrown a little deeper but QuickBuilder:627 kicks it off)
r
Oh I see what you saying.
.Y()
returns the relationship instance whereas,
.getY()
would return the entity instance. Somehow in quick 5 that method used to be forwarded onto the entity somehow but now it is not.
d
I claim that is a bug, but am looking to kick that idea around
e
If I’m understanding correctly, the fact that it worked before is the bug. Calling
.Y()
above returns a Relationship which in turn has a QuickBuilder associated with it. The only methods that will be looked up on the associated entity are scopes, methods that start with
scope***
. Now, I believe you are coming from v4. In v4 it worked because the entity held on to the builder. In v5 the builder was decoupled for performance reasons. At that point the long standing idea of only scopes being callable from a builder was enforced. It has always been the position of the docs that scopes are the only functions on an entity that can be called from builders. Does that help clear things up?
d
"cannot invoke non scope* prefixed methods on the results of a relationship" is the clarity I needed, thanks
e
To be clear, by “the results of a relationship” you are referring to the relationship components returned by Quick.
r
@David Rogers also it seems you are trying to selectively disable global scopes. There is a feature for this, however Im not 100% sure if global scope activate on relationship instances.
e
If you called
get{relationshipName}
you would have either an entity or array of entities and the method would work just like any other method.
d
well, I want the builder (
Y
not
getY
), and I want to configure the builder, to not use any global scopes, so probably, haha,
function scopeNoGlobalScope()
is the new hotness
e
The
withoutGlobalScopes
method that @Ryan Albrecht mentioned would be an option as well.
d
do all global scopes need to be mentioned by name there? Or can I just say "none, doesn't matter what their names are"
r
@elpete i assume that would look something like
getInstance("X").firstOrFail().Y().withoutGlobalScopes([names]).get()
d
i guess I could try it without pestering
r
Looking at the source code, scope names are required. Would nice to have to option to deactivate all them. I feel a pull request coming on
e
Ha ha. Sounds reasonable. The way it is currently implemented it would need some sort of wildcard marker.
I’m curious — how many global scopes are we talking about here?
d
I had just started looking into that. They're invoked in groups, so actual scope names are elsewhere. The idea had been to just skip them:
Copy code
function applyGlobalScopes( qb ) {
  if (this.NO_GLOBAL_SCOPES_ ?: false) {
    return
  }
  qb.addABunchOfSubselects1()
  qb.addABunchOfSubselects2()
  ...
}
function NO_GLOBAL_SCOPES() { this.NO_GLOBAL_SCOPES_ = true; return this; }
roughly ~10 probably
👍 1
this seems to patch it up, is it safe to assume we can write into
this
and get the same
this
in applyGlobalScopes?
Copy code
function scopeNoGlobalScopes() { this.NO_GLOBAL_SCOPES_ = true; }
r
@elpete what do you think about this. Add a new private variable to the QuickBuilder called
_globalScopeExcludeAll
which is defaulted to false. The
withoutGlobalScope
method now has an optional parameter. If no parameter is passed in then set this private variable to true. Do a check on ``_globalScopeExcludeAll` ` before applying global scopes. Check line 1027 and line 1047 in the below image
image.png
e
It looks good. Add a test and we should be good. 👍🏻
r
@elpete it seems there is some weird caching behavior with quick mementos. In regards to the below code. If a global scope is applied that adds a virtual attribute, subsequent entity retrievals that exclude the global scope will still have that key defined in the memento (with a value of undefined)
image.png
Off the top of your head do you know if any caching issues that would cause this?
e
That should be resolved in v6. Are you based off of the latest code?
r
I think so. Let me check and will get back to you
The was the issue fyi. Was working with old code :/