Skip to content

DB count() function returning data that diverges with ->get()->count() #56363

Discussion options

You must be logged in to vote

Test in v12.18.0:

We have a different pivot but the logic is the same.
We also have unique on the pair of ids in the pivot unlike the issue but the seeder from the issue populates the table with unique pairs anyway BUT the results described in the query say that there are duplicates in the db (not in the seeder):

echo OperationProductPivot::query()->where('product_id',$i)->count() . "\n";
echo OperationProductPivot::query()->where('product_id', $i)->whereHas('operation')->count() . "\n";
echo OperationProductPivot::query()->where('product_id', $i)->whereHas('operation')->get()->count() . "\n";
echo '-------------------- Until here, everything looks normal, but:' . "\n";
logger('----------…

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@crazynds
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by crazynds
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #56360 on July 22, 2025 02:37.