Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In loopback 4, Hasmany relation returns undefined instead of empty array when there is no related data #592

Open
nehemiekoffi opened this issue Jun 9, 2024 · 0 comments
Labels

Comments

@nehemiekoffi
Copy link

nehemiekoffi commented Jun 9, 2024

Steps to reproduce

Query data by including hasmany relation..

// Exemple
result = await this.authorRepository.findOne({ where: { id : '<authorId>'}, include:['books']  })

Current Behavior

in the result, you will notice that books is undefined for authors who dont have any books.

[
  {
  id : 'xxxx',
  name : 'abc',
  # books is undefined 
 },
 {
  id : 'xxxx',
  name : 'abc',
  books : [
  {
    id : 'xxxxx',
    title : 'zzzzz'
   }
  ]
 }
]

Expected Behavior

Books should return empty array for authors who don't have books. it was like that in loopback 3.

[
  {
  id : 'xxxx',
  name : 'abc',
  books : [] #should be like that
 },
 {
  id : 'xxxx',
  name : 'abc',
  books : [
  {
    id : 'xxxxx',
    title : 'zzzzz'
   }
  ]
 }
]

Link to reproduction sandbox

Additional information

Related Issues

See Reporting Issues for more tips on writing good issues

@nehemiekoffi nehemiekoffi changed the title In loopback 4, Has many relation relation returns undefined instead of empty array when there is no related data In loopback 4, Has many relation returns undefined instead of empty array when there is no related data Jun 9, 2024
@nehemiekoffi nehemiekoffi changed the title In loopback 4, Has many relation returns undefined instead of empty array when there is no related data In loopback 4, Hasmany relation returns undefined instead of empty array when there is no related data Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant