groupby / having query no longer working
-
We have a web site at https://www.walksinspain.org which is built around a database of Walks in Spain, implemented using Pods.
Each “Walk” is a Custom Post Type, and is related via a Relationship field type to a Custom Taxonomy called “Area” which represents an area of Spain.
The Area of a Walk is a mandatory field.In a couple of places, including the Search facility, we do a query to find which Areas contain Walks, as follows:
$walkareas = pods('walk'); $params = array( 'select' => 'walk_area.name as areaname, count(*) as total', 'groupby' => "walk_area.name", 'having' => 'count(*) > 0', 'expiry' => 300); // keep in cache for 5 minutes in case the user makes several searches $walkareas->find($params); while ($walkareas->fetch()) { $area_name = $walkareas->field('areaname'); ... }
where
walk_area
is the field of the Walks pod which relates to the Area record.The query returns a number of records, but for the last
fetch()
theareaname
returned is a null string instead of ‘Pyrenees Central’.When I do other queries, eg to produce an export of the Walks, which includes the code
$walk = pods( ' walk' ); $params = array( 'limit' => -1, 'orderby' => 'post_title'); $walk->find($params); while ($walk->fetch()) { $title = $walk->field('post_title'); $area = $walk->field('walk_area.name'); ...
everything works as expected, and ‘Pyrenees Central’ is returned for walks in that area.
This all did work in the recent past, but not sure when exactly it broke, but probably in one of the pods 2.8 releases.
On my dev machine I have the same code but different data, and it works fine there, so I’m wondering has one of the internal pods records got corrupted.
Is there some utility to check if all the internal data is consistent, and how would I go about trying to fix it if it were corrupt?
I have tried clearing caches (including pods caches) and have tried changing the Area field of a walk to another area and then back again.
Any ideas? – thanks for your help!
- The topic ‘groupby / having query no longer working’ is closed to new replies.