Open xreader opened 10 years ago
There is no api for removing associations right now, you have to find the associated model's id and delete it.
ok, but It is not possible in my case because the model from association belongs to another items
Actually there is an API for removing associations, which I snuck into the release branch a few weeks ago: https://github.com/mde/model#removing-associations
Let me know if it works okay for you. :)
@mde Hi, i updated model to 0.4.15 but i still get exception TypeError: Object {..} has no method 'removeParent'
var Name = function () {
...
this.hasOne('Generic');
}
var Generic = function () {
...
this.belongsTo('Name');
}
, 'test remove association to genus from name': function (next) {
var name = geddy.model.Name.create({name: "demecus"});
name.save(function (err, data) {
var parent = geddy.model.Name.create({name: "Tree"});
name.setParent(parent);
name.save(function (err, data) {
name.removeParent(parent, function (err) {
next();
});
});
});
}
The model names in the test don't seem to be the same as the definitions. You have two instances of Name, where one is trying to set the 'parent' association on the other. From the definitions, it looks like you should have a Name and a Generic, and have the Name instance do setGeneric on the Generic instance.
We do have a few basic tests for the remove API, and they are passing: https://github.com/mde/model/blob/master/test/integration/adapters/shared.js#L928
Oh wow, a surprise feature :D
I have two models that are associated with hasOne / belngsto relation
In documentation is described the "set" and "get" API methods but how can one remove item from associaton or is it only possible to override it with another item?
Here is one test that fails