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
Collection returns empty object for null relations #1771
Comments
+1 - we are getting around it by checking Bookshelf has really come on in leaps and bounds over the past 18 months, so I know it's only a matter of time before this is fixed 🤗 |
Im using version 14.2 and im having this exact problem...
And that is returning for users with related data (Its OK):
But is returning empty obejct { } for users with no related data
Any ideas? |
Any updates? I also reported this problem on #1299 (comment). |
How can there be any updates if you just reported the issue? Can you create a new issue explaining the problem with steps to reproduce? |
Thanks for the quick response. It's not just me, the @cacharrin also reported the same problem after #1299 was fixed. I will try to create a small sample project. |
Also reported this kind of issue on #2090. I have researched many times it not resolved. please tell me if anyone knows, how to solve it. to achieve this I used knex but need full code to restructure. But I believe there is some way in bookshlef to do this |
Introduction
collection with
hasOne
relation returns empty objects instead ofnull
Issue Description
If you have a collection with a
hasOne
relation and you fetch that relation withwithRelated
onfetchAll
the relations that come out to be null are not null but have an empty object instead.Steps to reproduce issue
Suppose you have a model like:
And you do:
User.fetchAll({ withRelated: ['location'] })
. What you'll get is:Expected behaviour
location
should benull
instead of a truthy object like withbelongsTo
.Actual behaviour
location
are empty objects which makes it difficult to doif(user.location)
.The text was updated successfully, but these errors were encountered: