Related models are empty objects instead of null when not found
See original GitHub issueI don’t know if there is a practical reason for this, but when using model.fetch({ withRelated: ['otherModel'] })
, the results for rows that did not have an otherModel relation have the property otherModel
set to {}
, an empty object. Shouldn’t this field be set to null
? And if not, why is an empty object the preferred representation of a non-existent relation over false
, null
or undefined
?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How to show empty object instead of NULL when the one To ...
Hello , in my controller I return users with 'groups' and 'sidnfo' models . the module 'sdinfo' in one to one relationship, public...
Read more >Gorm return empty object instead default object when value is ...
GORM is returning an empty object; when it comes to Go values, "empty" and "default" are the same, and are actually called the...
Read more >Filtering for Empty or Null Values in a Django QuerySet - Chartio
Easily the most important method when working with Django models and the underlying QuerySets is the filter() method, which allows you to generate...
Read more >How to return a empty object when linq query yields nothing ...
I'm trying to query the database using linq query and the FirstOrDefault yields null value. Is there a way I can return a...
Read more >When to use NULL and when to use an empty string?
It does. Now looking at DBMS where '' is not identical to NULL (e.g. SQL-Server). Working with '' is generally easier and in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We’ve also encountered this. Here are some of my findings:
This problem still persists in
1.0.0
,1.0.1
e1.1.0
, withfetchPage
.For example: If in a list one record has a relation, all others records has an empty property.
If no one has a relationship, then the relation property is omitted.
cc @edvaldoszy