You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
load() has loadMissing(). If there is a functionality to only load relationships if not already present, I think it would be just fair to provide the same possibility for relationship aggregates (lazy loading relationship counts if missing etc). Use cases should also be similar to the ones loadMissing() has I guess.
I'm personally looking for it because my application makes use of service classes. One issue I see with that is possibly creating a load of database queries throughout the process in some scenarios.
Assuming I have a method like this:
/** * Retrieve the amount of affiliates the advertiser has. * * @return int */publicfunctiongetAffiliateCount(): int
{
return$this->user->activatedAffiliates()->count();
}
Prepending the main line with a loadMissingCount() is what I am looking to do.
This would allow me to not run into an issue with one single user being processed like this as I don't have to worry about the count being eager loaded, but also enables me to eager load the relationship in previous steps for a collection of users and have them being passed over to the method one by one, let it do it's thing (and possibly more, this is a simplified example) and not load the count another time.
Update: This is similar to what I am looking for, but just having the method above would be much more elegant and have the same data attribute naming convention with the underscore as it would with have with regular eager loading in the first place.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I searched for
loadMissingCount
in issues, the discussion board and Google. I only found a Tweet: https://mobile.twitter.com/gdebrauwer/status/1427294207429992452load()
hasloadMissing()
. If there is a functionality to only load relationships if not already present, I think it would be just fair to provide the same possibility for relationship aggregates (lazy loading relationship counts if missing etc). Use cases should also be similar to the onesloadMissing()
has I guess.I'm personally looking for it because my application makes use of service classes. One issue I see with that is possibly creating a load of database queries throughout the process in some scenarios.
Assuming I have a method like this:
Prepending the main line with a
loadMissingCount()
is what I am looking to do.This would allow me to not run into an issue with one single user being processed like this as I don't have to worry about the count being eager loaded, but also enables me to eager load the relationship in previous steps for a collection of users and have them being passed over to the method one by one, let it do it's thing (and possibly more, this is a simplified example) and not load the count another time.
Update: This is similar to what I am looking for, but just having the method above would be much more elegant and have the same data attribute naming convention with the underscore as it would with have with regular eager loading in the first place.
Beta Was this translation helpful? Give feedback.
All reactions