diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index fd26904cf3..04988c1cda 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -402,6 +402,9 @@ Zotero.Item.prototype.loadFromRow = function(row, reload) { this['_' + col] = row[col] ? parseInt(row[col]) : 0; break; + case 'sourceItemID': + this['_sourceItem'] = row[col] || false; + default: this['_' + col] = row[col] ? row[col] : ''; } diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index cca97c184a..8116c041ee 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -46,7 +46,7 @@ Zotero.Items = new function() { _primaryFields = Zotero.DB.getColumns('items'); _primaryFields.splice(_primaryFields.indexOf('clientDateModified'), 1); _primaryFields = _primaryFields.concat( - ['firstCreator', 'numNotes', 'numAttachments'] + ['firstCreator', 'numNotes', 'numAttachments', 'sourceItemID'] ); } @@ -749,7 +749,9 @@ Zotero.Items = new function() { + "(SELECT COUNT(*) FROM itemNotes INo WHERE sourceItemID=I.itemID AND " + "INo.itemID NOT IN (SELECT itemID FROM deletedItems)) AS numNotes, " + "(SELECT COUNT(*) FROM itemAttachments IA WHERE sourceItemID=I.itemID AND " - + "IA.itemID NOT IN (SELECT itemID FROM deletedItems)) AS numAttachments " + + "IA.itemID NOT IN (SELECT itemID FROM deletedItems)) AS numAttachments, " + + "(CASE I.itemTypeID WHEN 14 THEN (SELECT sourceItemID FROM itemAttachments IA WHERE IA.itemID=I.itemID) " + + "WHEN 1 THEN (SELECT sourceItemID FROM itemNotes INo WHERE INo.itemID=I.itemID) END) AS sourceItemID " + 'FROM items I WHERE 1'; if (arguments[0]) { sql += ' AND I.itemID IN (' + Zotero.join(arguments[0], ',') + ')';