zefhemel/persistencejs — Issue #57: .destroyAll() removes ALL Entities
Author: hennaTheGreat
Created: 2011-10-16 09:21:02+00:00
State: open

The documentation says:
"destroyAll([tx], callback) Asynchronously removes all the items in the collection. Important: this does not only remove the items from the collection, but removes the items themselves!"

Example:
// get the first 20 entities but skip the very first two
HistoryElement.all().order('lastUsedOn', false).limit(20).skip(2).list( function (r) {
console.log(r);
});

Generates the expected Queries (if you do not forgot the .limit() - otherwise it also does unexpected things):
SELECT `root`.id AS HistoryElement_id, `root`.`lastUsedOn` AS `HistoryElement_lastUsedOn`, `root`.`project` AS `HistoryElement_project`, `root`.`customer` AS `HistoryElement_customer`, `root`.`activity` AS `HistoryElement_activity`, `root`.`workingPeriod` AS `HistoryElement_workingPeriod` FROM `HistoryElement` AS `root` WHERE 1=1 ORDER BY `HistoryElement_lastUsedOn` DESC LIMIT 20 OFFSET 2 []

If I now want to delete all this (up to 18) entities after my first two I expect i can do it like that:
HistoryElement.all().order('lastUsedOn', false).limit(20).skip(2).destroyAll();

But this is the generated SQL:
SELECT id FROM `HistoryElement` WHERE 1=1 []
persistence.store.websql.js:78DELETE FROM `HistoryElement` WHERE 1=1 []

At this point all entities got lost.