hasMany relationships wrong delete behavior

Expected behavior

Schema example:

let _schema = new mongoose.Schema({
    tests: [{ type: mongoose.Schema.Types.ObjectId, ref: "Test" }]
}, {
    timestamps: true,
    usePushEach: true
});
const model = mongoose.model('User', schema);

It displays as expected the hasMany relationships in the UI.
When a Test document is assigned to a user, there is 2 delete actions available:

  • “Dissociate the relationship”
  • “Delete the test”

I expect:

  • the “Dissociate relationship” action to only remove the relationship in my User document and keep the Test document.
    Request: DELETE /forest/Client/:clientId/relationships/screeningTests?delete=false

  • the “Delete the screening test” to remove the relationship in my User and also the Test document.
    Request: DELETE /forest/Client/:clientId/relationships/screeningTests?delete=true

Actual behavior

Whether we select the “Dissociate the relationship” or “Delete the test” action, the same request is sent: DELETE /forest/Client/:clientId/relationships/screeningTests?delete=true

When looking at my database, the Test document is always removed but the relationship is not removed from the User.

Context

"meta": {
    "database_type": "MongoDB",
    "liana": "forest-express-mongoose",
    "liana_version": "6.3.8",
    "engine": "nodejs",
    "engine_version": "10.22.1",
    "framework": "other",
    "framework_version": null,
    "orm_version": "5.10.8"
  }

Hi @Florian_Belliard !
I’m not able to reproduce, but it might depends on multiple things, can you share a document of both the collections please ? What DB are you using (self-hosted mongoDB, mongo Atlas…)

Hi @Nicolas_Sailly,

Since I’m using custom components to generate the smart fields, I’ll directly share the JSON generated from the .forestadmin-schema.json. Hope it’ll be enough for your tests:

collections.tar.gz (2.5 KB)

I’m using a self-hosted mongoDB on docker (mongo:4.2).

Hey @Florian_Belliard,

I did try to reproduce your issue and it works perfectly fine for me too.
I also looked into the code there is normally absolutely no way that ?delete=true appears in the url when dissociating records.
Are you sure you did not juste made a miss click :thinking:?

But I do confirm that when removing a record the association is not removed :disappointed:. I’ll create a bug ticket accordingly

You can keep track on this ticket here: