Fix section preload in people search

This commit is contained in:
William Bouzourène 2025-06-27 11:43:06 +02:00
parent 183415912f
commit 56fd3c0952
Signed by: bouzoure
SSH key fingerprint: SHA256:19MbXpLua4rUtk8tunMesD8KUKb91LXLHg8E/qTooww

View file

@ -45,11 +45,9 @@ func PeopleSearch(params PeopleSearchParams) (PeopleSearchResults, error) {
// SQL qeury for results // SQL qeury for results
sqlQuery := ` sqlQuery := `
SELECT people.*, SELECT people.*
sections.name AS Section__name
FROM people FROM people
INNER JOIN sections `
ON people.section_id = sections.id`
// SQL query to count results // SQL query to count results
sqlQueryCount := ` sqlQueryCount := `
@ -354,12 +352,12 @@ func PeopleSearch(params PeopleSearchParams) (PeopleSearchResults, error) {
%s %s
%s %s
%s %s
GROUP BY people.id, Section__name GROUP BY people.id
ORDER BY CONCAT(people.last_name, people.first_name) ASC ORDER BY CONCAT(people.last_name, people.first_name) ASC
%s %s
`, sqlQuery, sqlFieldJoins, sqlFilters, sqlPagination) `, sqlQuery, sqlFieldJoins, sqlFilters, sqlPagination)
sqlResult := db.Raw(sqlQuery, sqlParams...).Scan(&results.Results) sqlResult := db.Raw(sqlQuery, sqlParams...).Preload("Section").Find(&results.Results)
if sqlResult.Error != nil { if sqlResult.Error != nil {
return results, sqlResult.Error return results, sqlResult.Error
} }