Virtual list creates circular reference error when trying to include virtuals in query result
See original GitHub issueHey,
on a List register there’s a piece of code that adds ‘list’ as a virtual field.
this.schema.virtual('list').get(function () {
return list;
});
This creates some problems when you add your own virtuals and want them included in query result you’re going to parse to JSON (for an API endpoint for example).
Take this example:
var Waypoint = new keystone.List('Waypoint', {
autokey: { path: 'slug', from: 'name', unique: true }
});
...
//Check if waypoint is available
Waypoint.schema.virtual('available').get(function() {
console.log('Calling available getter');
if(this.conditionsOn) {
return availabilityUtils.check(this.conditions.days, this.conditions.start, this.conditions.end);
} else {
return true;
}
});
...
Waypoint.schema.set('toJSON', {
virtuals: true
});
Waypoint.addPattern('standard meta');
Waypoint.defaultColumns = 'title, type';
Waypoint.register();
In this case, querying a waypoint and returning it with res.apiResponse()
calls the Object.stringify
method but generates an TypeError: Converting circular structure to JSON
error because of the list virtual.
Best practices or workarounds?
Kind regards, David
Issue Analytics
- State:
- Created 9 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Remove or allow a circular reference - Microsoft Support
If you suspect you have a circular reference in a cell that isn't showing a zero, try this: Click the formula in the...
Read more >How to fix a circular reference in Excel - Spreadsheet Class
This causes a circular reference error. To fix this error, simply add the tab name to the references in the filter formula. The...
Read more >A circular reference was detected while serializing an object of ...
It seems that there are circular references in your object hierarchy which is not supported by the JSON serializer.
Read more >Circular Reference Error in Excel and How to Fix it (+ video ...
A Circular Reference is a type of error in Excel that happens when a formula in a cell tries to calculate itself. Essentially...
Read more >mongoose/index.d.ts at master - GitHub
// interface breaks on Mongoose Document class due to circular references. // Re-evaluate this when we drop `extends Document` support in document interfaces....
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 FreeTop 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
Top GitHub Comments
Just in case that someone needs a quick & dirty fix for this, I’ve created a gist with a code that deletes every
list
inside the model prior to export it: https://gist.github.com/ignlg/519a4b6b9845d7442a48Hope it helps meanwhile.
Thanks @ignlg for your gist, thos fixed my problem!