Using Quick and have a question. I have a FoundIte...
# box-products
d
Using Quick and have a question. I have a FoundItem model. I don’t ever want to get a FoundItem with certain statuses (NULL and P are ok, basically). I know on the handler I can do this…
Copy code
var foundItem = getInstance( 'FoundItem' )
    .where( 'id', rc.id )
    .whereRaw( 'NVL(status, ''P'') = ''P''' )
    .firstOrFail()
    .getMemento();
But is there a way to just put this on my Quick Model directly so that it never tries to bring back a record with any other status and we don’t have to deal with it all over the place? That way I could just do
var foundItem = getInstance( 'FoundItem' ).findOrFail( rc.id ).getMemento();
instead anywhere we need one. Thoughts?
s
yep, make a scope that does it and add that scope to
applyGlobalScopes()
d
Ok, cool. Thanks for the direction, reading through the docs on that topic.
Yep, that’s the ticket! Thanks @sknowlton, worked great.
Circling back on a similar conversation about relationships (link below), the scope seems to be a bit cleaner to me so I’ve changed that around to use scopes too. https://cfml.slack.com/archives/C06TSRXCJ/p1654297509170339
Thanks for the tip!