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

RangeError: Maximum call stack size exceeded when trying to write to non-existent field #112

Open
Billydubb opened this issue Sep 6, 2017 · 1 comment

Comments

@Billydubb
Copy link

Below is the full working example that leads to the following error.
The problem is that company defines a field named employees but in the example I am trying to assign a value to employee.
I was hoping that programmer errors like these would be part of the errors that the ORM/ODM would catch.

RangeError: Maximum call stack size exceeded
    at deepCopy (/Users/kelvin/node_modules/nedb/lib/model.js:128:22)
    at /Users/kelvin/node_modules/nedb/lib/model.js:130:18
    at Array.forEach (native)
    at deepCopy (/Users/kelvin/node_modules/nedb/lib/model.js:128:22)
    at /Users/kelvin/node_modules/nedb/lib/model.js:130:18
    at Array.forEach (native)
    at deepCopy (/Users/kelvin/node_modules/nedb/lib/model.js:128:22)
    at /Users/kelvin/node_modules/nedb/lib/model.js:122:41
    at Array.forEach (native)
    at deepCopy (/Users/kelvin/node_modules/nedb/lib/model.js:122:9)
var connect = require('camo').connect;
var Document = require('camo').Document;

var database;
var uri = 'nedb://companies';


class Company extends Document {
    constructor() {
        super();

        this.name = String;
        this.employees = [Employee];
    }

    static collectionName() {
        return 'companies';
    }
}


class Employee extends Document {
    constructor() {
        super();

        this.name = String;
        this.company = Company;
    }

    static collectionName() {
        return 'employees';
    }
}


connect(uri).then(function(db) {
    database = db;
	const comp = Company.create({name: 'Company inc.'});
	const employee = Employee.create({name: 'peter'});
	comp.employee = [employee];
	employee.company = comp;

	comp.save()
	.catch(err => {
		console.log(err);
	});
});
@harrychiling
Copy link

Your Employee class shoul extend the EmbeddedDocument class which needs to be pulled in.

//add this to top
var EmbeddedDocument = require('camo').EmbeddedDocument;

//change this
class Employee extends Document {

//to this
class Employee extends EmbeddedDocument {

//change this
var uri = 'nedb://companies';

//to this
var uri ='nedb:///companies';

Im also not sure you can have circular references like the employee.company tryin to save an employee object inside a company object that has an array of an employee object is probably not going to work. Other than that your code looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants