0

Problem

I'm using Strapi v5 with SQLite database. My Wine content type has many-to-one relations to Category and Region, but these relations are never populated in API responses, regardless of the populate syntax used.

Environment

  • Strapi: v5
  • Database: SQLite
  • Node.js: v22.13.1

Schema Configuration

Wine schema:

{
    "category": {
        "type": "relation",
        "relation": "manyToOne",
        "target": "api::category.category",
        "inversedBy": "wines"
     },
     "region": {
          "type": "relation",
          "relation": "manyToOne",
          "target": "api::region.region",
          "inversedBy": "wines"
     }
}

Category and Region schemas are standard with oneToMany back-references.

What I've Verified

✅ Permissions: All roles have find/findOne enabled for Wine, Category, Region

✅ Database: Relations exist in wines_category_lnk and wines_region_lnk tables

✅ Admin UI: Relations display correctly in Content Manager

✅ Server restarts: Multiple times after schema changes

API Calls Tested

All return wines without relations:

GET /api/wines?populate=\*
GET /api/wines?populate\[category\]=*&populate\[region\]=*
GET /api/wines?populate\[category\]=true&populate\[region\]=true
GET /api/wines?populate\[0\]=category&populate\[1\]=region
GET /api/wines?populate=category,region

Sample response:

{
    "data": [
        {
            "id": 193,
            "name": "Château Margaux",
            "price": 850,
            "createdAt": "2025-09-15T08:06:26.672Z"
          // category and region fields completely missing
        }
    ]
}

Database Verification

Relations DO exist in database:

sqlite\> SELECT \* FROM wines_category_lnk WHERE wine_id = 193;
188|193|121|1.0
sqlite\> SELECT \* FROM wines_region_lnk WHERE wine_id = 193;
128|193|111|1.0

Workaround That Works

Using direct database queries in a custom controller:

export default factories.createCoreController('api::wine.wine', ({ strapi }) =\> ({
async find(ctx) {
const results = await strapi.db.query('api::wine.wine').findMany({
populate: {
category: true,
region: true,
},
});

      return { data: results, meta: { pagination: {...} } };
    },

}));

This returns wines with relations correctly populated.

Question

Why don't standard Strapi v5 API populate queries work, while direct strapi.db.query() calls do? Is this a known bug or am I missing something in the configuration?

1 Answer 1

0

SOLVED - The issue was caused by custom route configuration.

In src/api/wine/routes/wine.ts, I had a custom config that was disabling middlewares and policies:

export default factories.createCoreRouter('api::wine.wine', {
    config: {
        find: { auth: false, policies: \[\], middlewares: \[\] },
        findOne: { auth: false, policies: \[\], middlewares: \[\] },
    }
});

This configuration was preventing populate from working. By reverting to the default config:

export default factories.createCoreRouter('api::wine.wine');

The populate now works perfectly! Strapi's internal middlewares are required to properly process populate parameters.

Lesson learned: Be careful with custom route configurations as they can break Strapi's native functionalities like populate.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.