Fix alphabetical sorting of child attachments in new databases

Broken after global schema introduction
This commit is contained in:
Dan Stillman 2021-04-18 01:43:37 -04:00
parent 633710c90b
commit 749e28dc1f
3 changed files with 49 additions and 2 deletions

View file

@ -1749,7 +1749,10 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
//
if (!isNew) {
// If attachment title changes, update parent attachments
if (this._changed.itemData && this._changed.itemData[110] && this.isAttachment() && parentItemID) {
let titleFieldID = Zotero.ItemFields.getID('title');
if (this._changed.itemData
&& this._changed.itemData[titleFieldID]
&& this.isAttachment() && parentItemID) {
reloadParentChildItems[parentItemID] = true;
}
}

View file

@ -598,11 +598,12 @@ Zotero.Items = function() {
//
// Attachments
//
var titleFieldID = Zotero.ItemFields.getID('title');
var sql = "SELECT parentItemID, A.itemID, value AS title, "
+ "CASE WHEN DI.itemID IS NULL THEN 0 ELSE 1 END AS trashed "
+ "FROM itemAttachments A "
+ "JOIN items I ON (A.parentItemID=I.itemID) "
+ "LEFT JOIN itemData ID ON (fieldID=110 AND A.itemID=ID.itemID) "
+ `LEFT JOIN itemData ID ON (fieldID=${titleFieldID} AND A.itemID=ID.itemID) `
+ "LEFT JOIN itemDataValues IDV USING (valueID) "
+ "LEFT JOIN deletedItems DI USING (itemID) "
+ "WHERE libraryID=?"