F
Filament10mo ago
Oddman

Rows not showing in list view after modifying query

I have a weird problem. I added a scope to my Galaxy model that is applied for the list view. That code looks like the following:
public function table(Table $table): Table
{
return $table->modifyQueryUsing(function(Builder $query) {
$query->countStructures();
});
}
public function table(Table $table): Table
{
return $table->modifyQueryUsing(function(Builder $query) {
$query->countStructures();
});
}
The resulting query, looks like this:
select "galaxies".*, (select COUNT(sectors.id) from "sectors" where sectors.galaxy_id = galaxies.id) as "sectors", (select COUNT(systems.id) from "systems" where systems.galaxy_id = galaxies.id) as "systems", (select COUNT(celestial_bodies.id) from "celestial_bodies" where celestial_bodies.galaxy_id = galaxies.id and "celestial_bodies"."type" = ?) as "planets" from "galaxies" where "galaxies"."deleted_at" is null order by "galaxies"."id" asc limit 10 offset 0 ["planet"]
select "galaxies".*, (select COUNT(sectors.id) from "sectors" where sectors.galaxy_id = galaxies.id) as "sectors", (select COUNT(systems.id) from "systems" where systems.galaxy_id = galaxies.id) as "systems", (select COUNT(celestial_bodies.id) from "celestial_bodies" where celestial_bodies.galaxy_id = galaxies.id and "celestial_bodies"."type" = ?) as "planets" from "galaxies" where "galaxies"."deleted_at" is null order by "galaxies"."id" asc limit 10 offset 0 ["planet"]
This is all fine, and when I run the query in postgres, it shows the correct rows. But nothing is showing up in the list view (but the list view count is correct). There are no errors, no console errors, everything looks fine. Any ideas as to why this might be the case?
2 Replies
Oddman
Oddman10mo ago
Hmmm, just figured out it's got something to do with using the table() method on the list resource. If I remove that entirely, it works fine. Found the problem. The documentation is incorrect. What you need to do is actually return the query via the parent method call, like so:
public function table(Table $table): Table
{
return parent::table($table)->modifyQueryUsing(function(Builder $query) {
return $query->countStructures();
});
}
public function table(Table $table): Table
{
return parent::table($table)->modifyQueryUsing(function(Builder $query) {
return $query->countStructures();
});
}
Without this, something doesn't work properly.
cheesegrits
cheesegrits10mo ago
Hmm, I'm pretty sure the documentation is correct. Can you show your countStructures() method?