model: fix infinite loop on nestRemoting

Prevent endless recursion on nestRemoting calls for
two-way model links.
This commit is contained in:
Kevin Delisle 2018-02-06 16:57:22 -05:00 committed by Kevin Delisle
parent d23ff84587
commit 386615a1df
2 changed files with 5 additions and 1 deletions

View File

@ -873,7 +873,10 @@ module.exports = function(registry) {
var regExp = /^__([^_]+)__([^_]+)$/; var regExp = /^__([^_]+)__([^_]+)$/;
var relation = this.relations[relationName]; var relation = this.relations[relationName];
if (relation && relation.modelTo && relation.modelTo.sharedClass) { if (relation && relation._nestRemotingProcessed) {
return; // Prevent unwanted circular traversals!
} else if (relation && relation.modelTo && relation.modelTo.sharedClass) {
relation._nestRemotingProcessed = true;
var self = this; var self = this;
var sharedClass = this.sharedClass; var sharedClass = this.sharedClass;
var sharedToClass = relation.modelTo.sharedClass; var sharedToClass = relation.modelTo.sharedClass;

View File

@ -1480,6 +1480,7 @@ describe('relations - integration', function() {
Book.hasMany(Page, {options: {nestRemoting: true}}); Book.hasMany(Page, {options: {nestRemoting: true}});
Book.hasMany(Chapter); Book.hasMany(Chapter);
Page.hasMany(Note); Page.hasMany(Note);
Page.belongsTo(Book, {options: {nestRemoting: true}});
Chapter.hasMany(Note); Chapter.hasMany(Note);
Image.belongsTo(Book); Image.belongsTo(Book);