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

Maximum call stack size exceeded #2

Open
konsumer opened this issue Jan 23, 2015 · 2 comments
Open

Maximum call stack size exceeded #2

konsumer opened this issue Jan 23, 2015 · 2 comments

Comments

@konsumer
Copy link

Maybe this is coming from a lack of understanding of how it's supposed to work, but I can't seem to map multiple relationships & use cascadeSave():

var mongoose = require('mongoose');
var cascadingRelations = require('cascading-relations');

mongoose.connect('mongodb://localhost/relationships');

var sShow = new mongoose.Schema({
  _id: Number,    // the key in the other database
  title: String,  // the name
  slug: String    // can be used to get URL, images, etc
});

var sEpisode = new mongoose.Schema({
  _id: Number,     // the key in the other database
  title: String,   // the title of this episode
  season: Number,  // the season
  episode: Number, // the episode
  url: String,     // URL for downloading this
  show: { type: Number, ref: 'Show', $through: 'episodes' }
});

var sUser = new mongoose.Schema({
  email: {required:true, type:String, unique:true},
  watched: [{ type: Number, ref: 'Episode', $through:'watched' }],
  ignored: [{ type: Number, ref: 'Episode', $through:'ignored'  }],
  collected: [{ type: Number, ref: 'Episode', $through:'collected'  }],
  subscriptions: [{ type: Number, ref: 'Show', $through:'subscribed'  }]
});

sUser.plugin(cascadingRelations);
sEpisode.plugin(cascadingRelations);
sShow.plugin(cascadingRelations);

var User = mongoose.model('User', sUser);
var Show = mongoose.model('Show', sShow);
var Episode = mongoose.model('Episode', sEpisode);

var user = new User({email: '[email protected]'});

var show = new Show({
    _id: 481,
    title: 'Game of Thrones',
    slug: 'game-of-thrones'
});
show.save();

user._related = {
    subscribed: [show]
};

user._related.ignored = [
    {
        "_id": 45305,
        "show": 481,
        "title": "Game of Thrones S03E09 HDTV x264-EVOLVE",
        "season": 3,
        "episode": 9,
        "url": "magnet:?xt=..."
    },
    {
        "_id": 44337,
        "show": 481,
        "title": "Game of Thrones S03E05 720p HDTV x264-IMMERSE",
        "season": 3,
        "episode": 5,
        "url": "magnet:?xt=..."
    }
];

user._related.collected = [
    {
        "_id": 55200,
        "show": 481,
        "title": "Game of Thrones S04E06 HDTV x264-KILLERS",
        "season": 4,
        "episode": 6,
        "url": "magnet:?xt=..."
    }
];

user._related.watched = [
    {
        "_id": 43700,
        "show": 481,
        "title": "Game of Thrones S03E02 720p HDTV x264-IMMERSE",
        "season": 3,
        "episode": 2,
        "url": "magnet:?xt=..."
    }
];

user.cascadeSave();

I get this:

...node_modules/cascading-relations/node_modules/q/q.js:514
    var deferred = object_create(defer.prototype);
                   ^
RangeError: Maximum call stack size exceeded
@konsumer
Copy link
Author

I am trying to map this relationship:
2015-01-23 03 16 39

@jraede
Copy link
Owner

jraede commented Jun 4, 2015

Just from your diagram it looks like you may have recursion going on. I didn't consider that when creating the package as I traditionally used it for hierarchical relations.

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

No branches or pull requests

2 participants