-
-
Notifications
You must be signed in to change notification settings - Fork 233
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
How to tell if we fetched zero related rows or we didn't fetch them at all #1014
Comments
This issue has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this issue will be closed. |
pokes the bot |
Sorry, I dont think use nil and []Type{} to differentiate logic is a good idea.
|
Me neither, but it was a workaround for something the ORM doesn't provide (is the sub-entity fetched or not?). I'm steering now towards a more inefficient and unsafer strategy of expecting the sub-entities to be already loaded. |
This issue has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this issue will be closed. |
Hi, I'm in the process of writing some code in a model that requires a related entity to be loaded (a calculation doing a summary), here's an example of the entity:
(unrelated but important too: I've seen in the doc slices declared as
[]*Type
instead of[]Type
, I believe the latter is the best practice since we don't require nil values in the slice, it'd be lovely if the docs were updated with this change or a good reason why we prefer slice pointers)My problem here is the following: If I call
GetServicesPrice()
I expectTaskServices
to be loaded. If by mistake the related entities are not fetched we risk having the function be like "sure the total is zero" without any error. What would be best in my opinion is to have a way for it to see whether:nil
)[]TaskServices{}
with zero length but declared)The scanner doesn't seem to make a difference, if it sees zero related entities it writes a
nil
, so in my getter there's no way to be absolutely sure we did load the related entities, and it smells like bugs waiting to happen. Javascript would haveundefined
for example.What do you guys think would be best in these cases? This is a scenario that keeps happening over and over, even with the old go-pg. Having a way to programmatically assert if sub-entities are loaded or not is pretty useful in my opinion.
Thanks!
The text was updated successfully, but these errors were encountered: