neumino / thinky

JavaScript ORM for RethinkDB
http://justonepixel.com/thinky/
Other
1.12k stars 128 forks source link

saveAll with sub relational document removal throwing validation Error. #612

Open valayDave opened 7 years ago

valayDave commented 7 years ago

The documentation for saving relational documents and deleting them shows the following:


var Advertizer = thinky.createModel("Advertizer", {
    name: type.string(),
});
var Contract = thinky.createModel("Contract", {
    advId: type.string(),
    dateTo: type.date(),
    dateFrom: type.date()
    regionId : type.string()
});

var Region = thinky.createModel("Region", {
    name: type.string(),
});

Advertizer.hasMany(Contract, "contracts", "id", "advId");
Contract.belongsTo(Advertizer, "advertizer", "advId", "id");

Region.hasMany(Contract, "contracts", "id", "regionId");
Contract.belongsTo(Region, "region", "regionId", "id");

Advertizer.get("3851d8b4-5358-43f2-ba23-f4d481358901").getJoin({contracts:true}).run()
    .then(function(adv) {

    adv.contracts.splice(1, 1);
    adv.saveAll({contracts: true}).then(function(newAdv) {

    }).error(function(err){

    });
});

When I do the adv.saveAll() I get a validation Error saying advId must be defined. I am doing it the same way it is shown on thinky documentation.

What can be the issue?

neumino commented 7 years ago

Maybe because id is not declared in your schema?