Document misleading : ctx.where.id in the before delete hook

19 views
Skip to first unread message

Hi Choi

unread,
Jun 17, 2017, 11:53:32 AM6/17/17
to loopb...@googlegroups.com
doc link : http://loopback.io/doc/en/lb3/Operation-hooks.html#before-delete

As the document says, before delete hook is called when the delete methods called. 

In the document, the author added this annotation with "Important" mark.

 Important:

The before delete operation hook does not receive a list of deleted model instance IDs, because backend data stores such as relational or NoSQL databases don’t provide this information. However, when deleting a single model instance hook receives ctx.where that contains the id of the instance being deleted.


If I understand correctly, the meaning of the annotation is this : 

When the PersistedModel.destroyAll method called, ctx.where has no 'id' property. 

When PersistedModel.prototype.destroy or PersistedModel.destroyById method called, there is ctx.where.id, and it's value is instance id.


But in some cases, the ctx.where.id works differently. In my cases, when the model is custom user model which inherited from User model, ctx.where.id is 'inq' filter, looks like this:


ctx : {

 where : {

     id: {

       inq: [1,2,3]

     }

  }

}


Very weird situation. I think that some inner changes are not reflected in the document.  

Reply all
Reply to author
Forward
0 new messages