Remove one or more members (e.g. a comment) from the specified collection (e.g. the
comments of BlogPost #4).
await Something.removeFromCollection(parentId, association) .members(childIds);
|1||parentId||The primary key value(s) (i.e. ids) for the parent record(s).
Must be a number or string (e.g.
Alternatively, an array of numbers or strings may be specified (e.g.
|2||association||The name of the plural ("collection") association (e.g. "pets")|
|3||childIds||The primary key values (i.e. ids) of the child records to remove. Note that this does not destroy these records, it just detaches them from the specified parent(s).|
|UsageError||Thrown if something invalid was passed in.|
|AdapterError||Thrown if something went wrong in the database adapter.|
|Error||Thrown if anything else unexpected happens.|
See Concepts > Models and ORM > Errors for examples of negotiating errors in Sails and Waterline.
For user 3, remove pets 99 and 98 from the "pets" collection:
await User.removeFromCollection(3, 'pets') .members([99,98]);
- This method can be used with
await, promise chaining, or traditional Node callbacks.
- If the association is "two-way" (meaning it has
via) then the child records will be modified accordingly. If the attribute on the other (e.g. "Pet") side is singular, the each child record's foreign key ("owner") will be set to
null. If it's plural, then each child record's collection will be modified accordingly.