0

For example consider the following setup:

    var Stuff = db.define('stuff', {
        title: {
            type: Sequelize.STRING(512),
        }
    });

    var Other = db.define('stuff', {
        title: {
            type: Sequelize.STRING(512),
        }
    });

    Stuff.belongsToMany(Other, {
        through: "OtherStuff",
        onDelete: "cascade"
    });
    Other.belongsToMany(Stuff, {
        through: "OtherStuff",
        onDelete: "cascade"
    });

Now how should I proceed to retrieve all Other not belonging to a given Stuff?

Coyote
  • 2,454
  • 26
  • 47
  • The one I can think of is first getting all that are associated with given Stuff, then use find with not it: `Other.find({ where: { id: { not: arrayOfIDs } } });` – Andrey Popov Jun 02 '15 at 13:54
  • This will help you: http://stackoverflow.com/questions/18838433/sequelize-find-based-on-association – Andrey Popov Jun 02 '15 at 13:59
  • This is my current workaround, but it requires retrieving all the objects associated with the current object first (which is not ideal as it will be a huge list within a few weeks) then sending a potentially huge list of IDs to back to the SQL server (not ideal either). The ideal solution would be notIn functions. I'll probably have to write custom SQL before we get there. – Coyote Jun 03 '15 at 09:31

0 Answers0