Sitemap
Ann R.

Ann R.

Backend | BI | Automation — Growing through every lesson in tech and life. For anything, hit me up at: r.ann98723@gmail.com

Member-only story

Eager Loading Constraints That Quietly Return the Wrong Rows

16 min readSep 13, 2026

Bob has no published posts but shows up in “users with published posts”. Why. 6 eager loading bugs + fixes, verified in PHP 8.3.

Press enter or click to view image in full size
Photo by Galt Museum & Archives on Unsplash

Here’s a data quality bug that survived production for months because everyone assumed the ORM was doing what the code looked like it said.

A SaaS platform has a dashboard showing “customers with active subscriptions”. Product manager wants a list: customer name, their subscription details, quick stats. Developer writes what looks obvious:

$customers = Customer::with(['subscriptions' => function ($q) {
$q->where('status', 'active');
}])->get();

Reviewer sees it, thinks “loading customers with their active subscriptions”. Merged. Deployed. Dashboard works — shows customers, shows their subscriptions. Product manager happy.

Six months later, sales team asks marketing to email “all customers with active subscriptions” a product announcement. Marketing uses the same dashboard filter. Sends the email to the list they see.

Complaints start coming in. Customers who canceled subscriptions months ago received the email. Some customers who never had ANY subscription received it. Some got it twice. Some active customers didn’t get it at all.

--

--

Ann R.
Ann R.

Written by Ann R.

Backend | BI | Automation — Growing through every lesson in tech and life. For anything, hit me up at: r.ann98723@gmail.com