Skip to content

useJoinTable: false on manyToOne relation break populate #13208

@vietlongn

Description

@vietlongn

Bug report

Required System information

  • Node.js version: 16
  • NPM version: 8.1.2
  • Strapi version: 4.1.9
  • Database: mysql/sqlite
  • Operating system: windows

Describe the bug

Add "useJoinTable": false to manyToOne relation break population when combined with select

Steps to reproduce the behavior

  1. Create audio content types with name attribute
  2. Create playlist content type with name, format attributes
  3. Create manyToOne relation on audio inversedBy audios on playlist, manually add "useJoinTable": false
  4. Query make a simple query on audio, select name and populate playlist
const entries = await strapi.db.query('api::audio.audio').findMany({
      limit: 10,
      select: ['name'],
      populate: {
        playlist: {
          select: ['name']
        },
      },

    })
  1. playlist not populated
[
  {
    "name": "a1",
    "id": 1,
    "playlist": null
  }
]

Expected behavior

playlist should be populated

[
  {
    "id": 1,
    "name": "a1",
    "playlist": {
      "name": "p1",
      "id": 1
    }
  }
]

Code snipets

audio schema:

{
  "kind": "collectionType",
  "collectionName": "audios",
  "info": {
    "singularName": "audio",
    "pluralName": "audios",
    "displayName": "audio",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "name": {
      "type": "string"
    },
    "playlist": {
      "type": "relation",
      "relation": "manyToOne",
      "target": "api::playlist.playlist",
      "inversedBy": "audios",
      "useJoinTable": false
    }
  }
}

playlist schema:

{
  "kind": "collectionType",
  "collectionName": "playlists",
  "info": {
    "singularName": "playlist",
    "pluralName": "playlists",
    "displayName": "playlist",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "name": {
      "type": "string"
    },
    "audios": {
      "type": "relation",
      "relation": "oneToMany",
      "target": "api::audio.audio",
      "mappedBy": "playlist"
    },
    "format": {
      "type": "enumeration",
      "enum": [
        "a",
        "b",
        "c"
      ]
    }
  }
}

Additional context

If select omitted, the playlist populated properly

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugIssue reporting a bugseverity: lowIf the issue only affects a very niche base of users and an easily implemented workaround can solvesource: core:databaseSource is core/database packagestatus: pending reproductionWaiting for free time to reproduce the issue, or more information

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions