vincent15000's avatar

withCount not the same value in local and production

Hello,

I have this code for the backend of an application Laravel / VueJS.

$student = Student::
    with('sessions')
    ...
    ->withCount(['notes' => function ($query) {
        $query->where('show', true);
    }])
    ->find($id);
return new StudentResource($student);
public function toArray($request)
{
    return [
        'id' => $this->id,
		...
        'notes_count' => $this->notes_count,
    ];
}

In local, notes_count equals 0 and in production equals 1.

Sure I have checked and there is in both cases 1 note.

That's the first time that I encounter such a problem with a difference between local an production.

UPDATED => The same query string on phpmyadmin local vs production doesn't give the same result 1 vs 0. So it's a problem with MySQL. But which one ?

Thanks a lot.

V

0 likes
5 replies
vincent15000's avatar

I would have added ->whenCounted('notes') in the resource, but the project is with the Laravel version 8 and ->whencounted() wasn't in this previous version.

vincent15000's avatar

I just checked the SQL query and I have executed it on phpmyadmin in local and in production.

In production, I get notes_count equals 0 whereas I really have a note.

What could perturb the query in MySQL ? (MariaDB in local)

vincent15000's avatar
vincent15000
OP
Best Answer
Level 63

Oh damn ... a simple id problem.

No problem with the database.

Please or to participate in this conversation.