diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index ae9007fb1..0244b578d 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -127,38 +127,6 @@ Zotero.Collection.prototype.getName = function() { } -/* - * Build collection from database - */ -Zotero.Collection.prototype.loadPrimaryData = Zotero.Promise.coroutine(function* (reload) { - if (this._loaded.primaryData && !reload) return; - - var id = this._id; - var key = this._key; - var libraryID = this._libraryID; - - var sql = this.ObjectsClass.getPrimaryDataSQL(); - if (id) { - sql += " AND O.collectionID=?"; - var params = id; - } - else { - sql += " AND O.libraryID=? AND O.key=?"; - var params = [libraryID, key]; - } - var data = yield Zotero.DB.rowQueryAsync(sql, params); - - this._loaded.primaryData = true; - this._clearChanged('primaryData'); - - if (!data) { - return; - } - - this.loadFromRow(data); -}); - - /* * Populate collection data from a database row */ diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js index f2b86ad8a..4ab4ba805 100644 --- a/chrome/content/zotero/xpcom/data/dataObject.js +++ b/chrome/content/zotero/xpcom/data/dataObject.js @@ -324,6 +324,60 @@ Zotero.DataObject.prototype._getLinkedObject = Zotero.Promise.coroutine(function return false; }); +/* + * Build object from database + */ +Zotero.DataObject.prototype.loadPrimaryData = Zotero.Promise.coroutine(function* (reload, failOnMissing) { + if (this._loaded.primaryData && !reload) return; + + var id = this.id; + var key = this.key; + var libraryID = this.libraryID; + + if (!id && !key) { + throw new Error('ID or key not set in Zotero.' + this._ObjectType + '.loadPrimaryData()'); + } + + var columns = [], join = [], where = []; + var primaryFields = this.ObjectsClass.primaryFields; + var idField = this.ObjectsClass.idColumn; + for (let i=0; i