Required Relation Field

Hi @iparker,

For debugging any Strapi server-side code I do the following (it gives you a full debugging experience):

  1. Use VSCode to open the project

  2. Open the terminal panel in VSCode (Terminal->New Terminal)

  3. On the Top Righthand side from the dropdown menu, select “Create JavaScript Debug Terminal”
    Screen Shot 2021-02-05 at 9.40.53 AM

  4. From that terminal run yarn strapi:develop

  5. Open the javascript file and set a breakpoint (click in the left margin next to the line number) - a red dot will appear
    Screen Shot 2021-02-05 at 9.48.51 AM

  6. Call the lifecycle event (via the browser or Postman etc)

  7. The debugger will pause at the breakpoint and you can inspect all the variables, stack, etc.

Just a note:

  1. The console events will be shown via the terminal that you use to run strapi (e.g. yarn strap:develop)
  2. The example code you have looks like it is for a model that has draft publishing enabled. If you are not using draft, then you should check the data object directly for the relation(s). If you are using draft, you should check to see if the data is just the publish date (see previous comments I made)
  3. If you only want to load one record, you can use .findOne(:id)
  4. There are other ways to debug the server-side code, but I think this is the easiest to setup.

Hope this helps :slight_smile:

3 Likes