{ "id": "114339", "key": "AC-2633", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "11", "description": "Is not a bug in our product", "name": "Not Our Bug" }, "resolutiondate": "2013-05-14T22:53:56.000+0000", "created": "2013-05-14T14:32:58.000+0000", "labels": [ "Alloy", "Backbone", "Get", "collection", "model" ], "versions": [], "issuelinks": [], "assignee": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2016-03-08T07:41:43.000+0000", "status": { "description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.", "name": "Resolved", "id": "5", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "14544", "name": "Alloy", "description": "Please enter tickets related to the Alloy here." } ], "description": "If I have a collection called catalogs and I want to get a model (id 1234) from that collection by id, based off of the documentation for backbone.js, I believe I should be able to:\r\n{code:js}\r\nvar selectedCatalogID = '1234'\r\nvar catalog = null; \r\ncatalog = catalogs.get(selectedCatalogID);\r\n{code}\r\nbut when I introspect catalog after this runs, its value is undefined;\r\n\r\nA work around I have been using is:\r\n{code:js}\r\nvar selectedCatalogID = '1234'\r\nvar catalog = null; \r\nfor (var i = 0, l = catalogs.models.length; i < l; i++){\r\n\tif (catalogs.models[i].id == selectedCatalogID){\r\n \t\tcatalog = catalogs.models[i];\r\n\t\tbreak;\r\n \t}\r\n}\r\n{code}\r\nwhich does work as expected, but isn't as clean as using backbone's collection.get();\r\n", "attachment": [], "flagged": false, "summary": "Alloy collection.get returning undefined", "creator": { "name": "jmoretti", "key": "jmoretti", "displayName": "Joe Moretti", "active": true, "timeZone": "America/Chicago" }, "subtasks": [], "reporter": { "name": "jmoretti", "key": "jmoretti", "displayName": "Joe Moretti", "active": true, "timeZone": "America/Chicago" }, "environment": "Mac OS 10.8.3, Titanium 3.1.0.GA, Alloy 1.1.2, iOS SDK 6.1, Titanium Studio build: 3.1.1.201305101132", "comment": { "comments": [ { "id": "251798", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "This would be better suited as a Q&A question as it is not clear to me that this is an issue with Alloy and/or Backbone versus perhaps an issue with your code. Please start with a Q&A question next time before escalating to a ticket.\n\nI'm guessing you are incorrectly using a string when you should be using an integer for the get() call. Though I am guessing because the code for your model has not been provided. I'll explain inline in the code you did provide:\n\n{code:javascript}\n// you are using a string for the ID here, which is fine, as long as \n// your ID is also a string field. If it is an integer, this will not \n// work in the subsequent get call. If it is an integer, you should be\n// using 1234 as the value, not '1234'.\nvar selectedCatalogID = '1234';\nvar catalog = null; \n\n// get() will do an === to get the appropriate model for you. This \n// means it will not be converting strings to integers for you, nor\n// vice versa, nor should it. \ncatalog = catalogs.get(selectedCatalogID);\n{code}\n\n{code:javascript}\nvar selectedCatalogID = '1234'\nvar catalog = null; \nfor (var i = 0, l = catalogs.models.length; i < l; i++){\n // this condition will match because you are using an == instead\n // of the === that catalogs.get() would use. It is casting the types\n // to allow comparison to occur between your given string and the\n // integer ID contained in the model. I'm assuming that if you changed\n // the == to === this would no longer work.\n if (catalogs.models[i].id == selectedCatalogID){\n catalog = catalogs.models[i];\n break;\n }\n}\n{code}", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-05-14T14:55:14.000+0000", "updated": "2013-05-14T14:55:14.000+0000" }, { "id": "251812", "author": { "name": "jmoretti", "key": "jmoretti", "displayName": "Joe Moretti", "active": true, "timeZone": "America/Chicago" }, "body": "I am sorry for not posting in the Q&A prior to creating an issue. I felt pretty confident this was a bug and that is why I started here. I tested with a === operator and the workaround continued to function properly. Additionally, I verified that catalogs.models[i].id is a string type. If you do not feel this is an issue, we can close it and I will repost to the Q&A.", "updateAuthor": { "name": "jmoretti", "key": "jmoretti", "displayName": "Joe Moretti", "active": true, "timeZone": "America/Chicago" }, "created": "2013-05-14T16:14:07.000+0000", "updated": "2013-05-14T16:14:07.000+0000" }, { "id": "251813", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Did you set the idAttribute of the model? It would help to see your model code.", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-05-14T16:21:38.000+0000", "updated": "2013-05-14T16:21:38.000+0000" }, { "id": "251817", "author": { "name": "jmoretti", "key": "jmoretti", "displayName": "Joe Moretti", "active": true, "timeZone": "America/Chicago" }, "body": "I am using a modified version of TiTouchDB (https://github.com/jmoretti/ti_touchdb/tree/attachmentFilePath) as the persistance adapter for my model.\n\n{code:js|title=Catalog.js}\nexports.definition = {\n\n config: {\n adapter: {\n type: \"titouchdb-catalog\",\n dbname: \"catalogs\",\n collection_name: \"catalogs\",\n views: [\n //listing only general catalogs for testing\n \t{ name: \"by_name\", map: \"function(doc) { if (doc.name) { emit(doc.name, null); } }\" }\n ],\n view_options: {\n prefetch: true\n },\n modelname: 'catalog'\n }\n },\n\n extendModel: function(Model) {\n _.extend(Model.prototype, {\n \tmap_doc: function(model, doc) {\n \tvar result = model;\n \tvar conflicts = doc.getConflictingRevisions(),\n \t\tnumConflicts = conflicts.length;\n \tif (numConflicts >1) {\n \t\t//list conflicts for diagnostics purposes\n \t\tfor(var i=0; i < numConflicts; i++){\n \t\t\tTi.API.info('document (model) conflicts: [' + i + '] ' + JSON.stringify(conflicts[i].properties));\n \t\t}\n \t\talert('There was a conflict. Resolving with: ' + JSON.stringify(conflicts[numConflicts-1].properties));\n \t\t//resolve conflict with last version in array\n \t\tdoc.resolveConflictingRevisions(conflicts, conflicts[numConflicts-1]);\n \t}\n \tvar attnames = (_.isUndefined(doc.currentRevision.attachmentNames)) ? [] : doc.currentRevision.attachmentNames;\n \t\tfor (var i = 0, l = attnames.length; i < l; i++){\n\t\t\tvar filePath = encodeURI('file://localhost'+doc.properties._attachments[attnames[i]].file_path);\n\t\t\tresult.set(attnames[i], filePath);\n\t\t}\n \treturn result;\n }\n });\n return Model;\n },\n\n extendCollection: function(Collection) {\n _.extend(Collection.prototype, {\n map_row: function(Model, row) {\n \tvar result = new Model(row.document.properties); \n \tvar conflicts = row.document.getConflictingRevisions(),\n \t\tnumConflicts = conflicts.length;\n \tif (numConflicts >1) {\n \t\t//list conflicts for diagnostics purposes\n \t\tfor(var i=0; i < numConflicts; i++){\n \t\t\tTi.API.info('document (collection) conflicts: [' + i + '] ' + JSON.stringify(conflicts[i].properties));\n \t\t}\n \t\talert('There was a conflict. Resolving with: ' + JSON.stringify(conflicts[numConflicts-1].properties));\n \t\t//resolve conflict with last version in array\n \t\trow.document.resolveConflictingRevisions(conflicts, conflicts[numConflicts-1]);\n \t}\n \tvar attnames = (_.isUndefined(row.document.currentRevision.attachmentNames)) ? [] : row.document.currentRevision.attachmentNames;\n\t\tfor (var i = 0, l = attnames.length; i < l; i++){\n\t\t\tvar filePath = encodeURI('file://localhost'+row.document.properties._attachments[attnames[i]].file_path);\n\t\t\tresult.set(attnames[i], filePath);\n\t\t}\n\t\treturn result;\n }\n });\n return Collection;\n }\n};\n{code}\n\nThe value of the catalogs collection right before the problem code is:\n{code:js}\n[\n {\n \"catalogType\": \"Hotspot\",\n \"publishDate\": \"2012-12-27T23:00:00\",\n \"creationDate\": \"2012-12-15T23:00:00\",\n \"type\": \"catalog\",\n \"sections\": [\n \"22a32b56-c1da-46f6-9e94-d7dea16b285e\",\n \"2a91e2fa-f1c9-4d88-9ec4-e507b18576ea\",\n \"4df27958-811e-415d-9b30-4d332b064579\",\n \"5c8f4a6c-d8c2-4930-bc4f-6c973642e1ba\",\n \"6d16258a-0c77-42b8-97cc-95db732ff58e\",\n \"7365fa92-0799-4179-b6f4-31d683828208\",\n \"8ace06aa-664d-4d9d-add8-5b5233bf5347\",\n \"92707359-189e-479e-8691-2855ffbfc93c\",\n \"a8fcee2c-091d-4f6a-8ece-98554eec04e8\",\n \"d340cac6-081f-48d2-a990-e304bc8db898\",\n \"d3a1db51-b128-487b-91ea-4cb827a0ac6d\",\n \"ebd2ab11-35b9-4542-a034-755a3543e7df\",\n \"f6c090cf-c7fc-4085-ab45-afb54a0fcd56\"\n ],\n \"_id\": \"f8142ebf-fa96-4707-9a81-d89eedced4c0\",\n \"creator\": \"Christina\",\n \"_rev\": \"4-78fa2c11f58b9eba5c52f19fb1f881c3\",\n \"expirationDate\": \"9998-11-30T23:00:00\",\n \"darkbackground\": true,\n \"name\": \"A. Two's Main 2013\",\n \"_attachments\": {\n \"cover\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/DA15CA95F8EB5F74DEA06B9A3813C3D2BEBF2387.blob\",\n \"stub\": true,\n \"revpos\": 2,\n \"length\": 119792,\n \"digest\": \"sha1-2hXKlfjrX3TeoGuaOBPD0r6/I4c=\"\n },\n \"cover_large\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/A2A93049663A9F750E557F01DF0F0781D06236CC.blob\",\n \"stub\": true,\n \"revpos\": 4,\n \"length\": 97665,\n \"digest\": \"sha1-oqkwSWY6n3UOVX8B3w8HgdBiNsw=\"\n },\n \"cover_thumb\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/5299B0F73C527D359D7C62AF21AC14C70DCEB878.blob\",\n \"stub\": true,\n \"revpos\": 3,\n \"length\": 25416,\n \"digest\": \"sha1-Upmw9zxSfTWdfGKvIawUxw3OuHg=\"\n }\n },\n \"cover\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/DA15CA95F8EB5F74DEA06B9A3813C3D2BEBF2387.blob\",\n \"cover_large\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/A2A93049663A9F750E557F01DF0F0781D06236CC.blob\",\n \"cover_thumb\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/5299B0F73C527D359D7C62AF21AC14C70DCEB878.blob\"\n },\n {\n \"_id\": \"298ecb2f-4bcc-4980-828b-5a80df46720c\",\n \"type\": \"catalog\",\n \"name\": \"Accents\",\n \"_attachments\": {\n \"cover\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/04FAC68D52A881C22A8742E7FDD28CFBC1F7FBAF.blob\",\n \"stub\": true,\n \"revpos\": 2,\n \"length\": 222833,\n \"digest\": \"sha1-BPrGjVKogcIqh0Ln/dKM+8H3+68=\"\n },\n \"cover_large\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/6331B2765CD00F38DF911681BEC1D2FD284DB6BC.blob\",\n \"stub\": true,\n \"revpos\": 4,\n \"length\": 61893,\n \"digest\": \"sha1-YzGydlzQDzjfkRaBvsHS/ShNtrw=\"\n },\n \"cover_thumb\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/B015619A9633535E9BBC30B467FC218AB6275EC9.blob\",\n \"stub\": true,\n \"revpos\": 3,\n \"length\": 18716,\n \"digest\": \"sha1-sBVhmpYzU16bvDC0Z/whirYnXsk=\"\n }\n },\n \"_rev\": \"4-03a35b8cfa34513eeed1454c3c85cfe2\",\n \"publishDate\": \"2012-12-13T23:00:00\",\n \"catalogType\": \"General\",\n \"expirationDate\": \"9998-11-30T23:00:00\",\n \"creationDate\": \"2012-12-13T23:00:00\",\n \"sections\": [\n \"00c738b9-925a-4308-a570-8a7845677319\",\n \"387f01fe-4738-4e2c-857a-97f6f287e72d\",\n \"4cfdb330-c202-41b1-9a03-2c659b1f2d2c\",\n \"5cc11859-83ca-4662-b77b-97268dd9dd45\",\n \"6021e408-4900-4e84-bffe-b8fe33ad63d5\",\n \"86f254db-8ff7-458a-90e6-f8e5752b804c\",\n \"8d8653f2-15c6-42ae-9d44-681cb4a67454\",\n \"92a78eff-c190-4d98-999f-b59b6572b09f\",\n \"9d8e4a85-38b7-4225-b0b4-0c6b3e6bed07\",\n \"a89e4bef-7d1a-49a0-8820-dd49631c26d7\",\n \"a9c3bc3e-c624-42a7-8012-dc2a95282bdd\",\n \"e17755ae-2180-4388-a276-a0c8bc770e78\",\n \"e9c4bb39-aae3-459c-a0de-dfbe52471aaa\"\n ],\n \"creator\": \"admin\",\n \"cover\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/04FAC68D52A881C22A8742E7FDD28CFBC1F7FBAF.blob\",\n \"cover_large\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/6331B2765CD00F38DF911681BEC1D2FD284DB6BC.blob\",\n \"cover_thumb\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/B015619A9633535E9BBC30B467FC218AB6275EC9.blob\"\n },\n {\n \"catalogType\": \"General\",\n \"publishDate\": \"2012-07-20T00:00:00\",\n \"creationDate\": \"2012-07-20T15:38:07.167\",\n \"type\": \"catalog\",\n \"sections\": [\n \"3b424529-4c42-407a-947b-bb5b95cec985\"\n ],\n \"_id\": \"f68b18db-e0dd-44db-a514-2db9037bc3e9\",\n \"creator\": \"tomg\",\n \"_rev\": \"2-339d5584594efacafc340ea330b05a65\",\n \"expirationDate\": \"9998-12-01T00:00:00\",\n \"darkbackground\": true,\n \"name\": \"atest2\",\n \"_attachments\": {\n \"cover\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/DA39A3EE5E6B4B0D3255BFEF95601890AFD80709.blob\",\n \"stub\": true,\n \"revpos\": 2,\n \"length\": 0,\n \"digest\": \"sha1-2jmj7l5rSw0yVb/vlWAYkK/YBwk=\"\n }\n },\n \"cover\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/DA39A3EE5E6B4B0D3255BFEF95601890AFD80709.blob\"\n },\n {\n \"catalogType\": \"Hotspot\",\n \"publishDate\": \"2012-12-27T23:00:00\",\n \"creationDate\": \"2012-12-17T23:00:00\",\n \"type\": \"catalog\",\n \"sections\": [\n \"59290806-55e4-4aa2-bba8-108420be193e\",\n \"6b02893f-6ad9-460c-bc0b-98f597fcf818\",\n \"b6c9d05a-18f7-453e-8750-1ff7973707bf\",\n \"b85de0ed-ce00-4312-a1bf-88bf700f18f5\",\n \"de75d20e-0f98-4c42-ad45-7c6d3a043373\",\n \"f0f8fdf9-c9bf-4da1-a5ff-486af862d9d5\",\n \"f1d69895-215c-4d5b-93ea-1e4eef878ac0\",\n \"f489640f-9fa4-4822-8968-f92de9df9b0c\",\n \"14622f9a-d609-46aa-855b-0b7ac68a6b32\",\n \"252233b6-a599-4cc5-ae19-8a70ad8d9e3b\",\n \"388dd707-5ec8-48f7-af20-b675864a0541\",\n \"3da850b1-56fd-424e-a047-163792cc3d51\",\n \"4c951fa0-aff2-4eab-8cbd-3a8ee0159a53\"\n ],\n \"_id\": \"a442d8c1-a950-405f-9ec0-d171f13e3573\",\n \"creator\": \"Christina\",\n \"_rev\": \"4-20e4ce76b84d61bc3b5cc1dd94272cd4\",\n \"expirationDate\": \"9998-11-30T23:00:00\",\n \"darkbackground\": true,\n \"name\": \"B. 2 Chic Spring Fashion 2013\",\n \"_attachments\": {\n \"cover\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/B3D02541F1C29EEB176FC097EDCB93FA88EDAD5E.blob\",\n \"stub\": true,\n \"revpos\": 2,\n \"length\": 94038,\n \"digest\": \"sha1-s9AlQfHCnusXb8CX7cuT+ojtrV4=\"\n },\n \"cover_large\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/83CB7D94DE9125292992F38D1239B1DD5F44CA2B.blob\",\n \"stub\": true,\n \"revpos\": 4,\n \"length\": 67571,\n \"digest\": \"sha1-g8t9lN6RJSkpkvONEjmx3V9Eyis=\"\n },\n \"cover_thumb\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/0ADCDC72F6608F5C35A4EB7EDAE95DB9FAB4935E.blob\",\n \"stub\": true,\n \"revpos\": 3,\n \"length\": 21323,\n \"digest\": \"sha1-CtzccvZgj1w1pOt+2uldufq0k14=\"\n }\n },\n \"cover\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/B3D02541F1C29EEB176FC097EDCB93FA88EDAD5E.blob\",\n \"cover_large\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/83CB7D94DE9125292992F38D1239B1DD5F44CA2B.blob\",\n \"cover_thumb\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/0ADCDC72F6608F5C35A4EB7EDAE95DB9FAB4935E.blob\"\n },\n {\n \"catalogType\": \"Hotspot\",\n \"publishDate\": \"2012-12-27T23:00:00\",\n \"creationDate\": \"2012-12-17T23:00:00\",\n \"type\": \"catalog\",\n \"sections\": [\n \"32a573a7-d940-4c6b-be5b-2bc3b95a1fbe\",\n \"41cdf654-e4dd-4241-9cac-1c90925843c7\",\n \"589cc0a8-396a-4f15-9dc1-06d4a955d72a\",\n \"9abdc12e-5dda-473c-bdf3-62d424f1c733\",\n \"9cc4bd62-06d3-4760-9b5e-275e4178a8f4\",\n \"9e0ee3c7-a1e1-4346-aa8b-321ea6a0d15a\",\n \"a99636ca-d60b-41ea-8d1a-4044f0039f9f\",\n \"c6a79351-e393-470d-b40b-9cc6605b92db\",\n \"e98036a8-e5ed-44d1-a723-2e3797c1d798\"\n ],\n \"_id\": \"06d30348-1561-4e98-884c-db6cf275d8ad\",\n \"creator\": \"Christina\",\n \"_rev\": \"4-808e0847db332fbb8ca3793dba2d1a8e\",\n \"expirationDate\": \"9998-11-30T23:00:00\",\n \"darkbackground\": true,\n \"name\": \"C. Cupcakes Main 2013\",\n \"_attachments\": {\n \"cover\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/83026ADD22FA71E5F5AC114DFEE7C140313C7427.blob\",\n \"stub\": true,\n \"revpos\": 2,\n \"length\": 87793,\n \"digest\": \"sha1-gwJq3SL6ceX1rBFN/ufBQDE8dCc=\"\n },\n \"cover_large\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/7676E3A28291BA476B672BBF9DFFCF6997F8C285.blob\",\n \"stub\": true,\n \"revpos\": 4,\n \"length\": 71977,\n \"digest\": \"sha1-dnbjooKRukdrZyu/nf/PaZf4woU=\"\n },\n \"cover_thumb\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/BBFB884070309F67F8CC0F6A5CC8D203569EFF74.blob\",\n \"stub\": true,\n \"revpos\": 3,\n \"length\": 23448,\n \"digest\": \"sha1-u/uIQHAwn2f4zA9qXMjSA1ae/3Q=\"\n }\n },\n \"cover\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/83026ADD22FA71E5F5AC114DFEE7C140313C7427.blob\",\n \"cover_large\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/7676E3A28291BA476B672BBF9DFFCF6997F8C285.blob\",\n \"cover_thumb\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/BBFB884070309F67F8CC0F6A5CC8D203569EFF74.blob\"\n },\n {\n \"catalogType\": \"Hotspot\",\n \"publishDate\": \"2012-05-23T23:00:00\",\n \"creationDate\": \"2012-05-17T23:00:00\",\n \"type\": \"catalog\",\n \"sections\": [\n \"cc84e463-d9d8-42be-a97a-2b035d7e01f2\",\n \"efb3dea4-e024-491c-83ee-fe86bda4e716\",\n \"f2d4379a-0412-456e-974f-25605a6b1f3b\",\n \"19009458-b1eb-4bc1-9c57-9d189dc61457\",\n \"3c8379f1-cd1c-42e7-9fb4-529323220f03\",\n \"4ce44fd4-d1fe-4305-a542-1dc72e909de3\",\n \"510ba0f0-536e-43fa-afb6-4d40630ba6f4\",\n \"6c6cfa79-71bd-4e86-b6c1-f780e1f06a44\",\n \"7c97e7b9-194f-43cd-8a26-cefa03c791c0\",\n \"803c4293-0c3f-46e8-ba02-a204774c1b6c\",\n \"86627474-d252-4c79-a334-de5e027d8ce0\",\n \"95e11abc-ce11-42af-a233-8ef590b826a8\",\n \"ad6d2b10-6fee-4f26-bb0d-cbcfdea370c7\",\n \"b8e9e67f-c352-476d-86a9-3112341897b6\",\n \"bde0947e-a13e-43d5-aa55-752775edad8c\"\n ],\n \"_id\": \"818218ff-1dc2-4a6f-81df-c612574b3622\",\n \"creator\": \"Christina\",\n \"_rev\": \"4-582ae6c352586e987c9a06fcb73b7bec\",\n \"expirationDate\": \"9998-11-30T23:00:00\",\n \"darkbackground\": true,\n \"name\": \"D. Tozai Home 2012-2013\",\n \"_attachments\": {\n \"cover\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/4F4C3B0B179D61E212CA5BE4F4BEB09B4B7C5E11.blob\",\n \"stub\": true,\n \"revpos\": 2,\n \"length\": 407961,\n \"digest\": \"sha1-T0w7CxedYeISylvk9L6wm0t8XhE=\"\n },\n \"cover_large\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/D161F6375E001A0678A50DBAEEEB3DF66DA88BA5.blob\",\n \"stub\": true,\n \"revpos\": 4,\n \"length\": 67104,\n \"digest\": \"sha1-0WH2N14AGgZ4pQ267us99m2oi6U=\"\n },\n \"cover_thumb\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/213CBA3128ED7F1E7A86D99882DAD3CAE1974C18.blob\",\n \"stub\": true,\n \"revpos\": 3,\n \"length\": 21211,\n \"digest\": \"sha1-ITy6MSjtfx56htmYgtrTyuGXTBg=\"\n }\n },\n \"cover\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/4F4C3B0B179D61E212CA5BE4F4BEB09B4B7C5E11.blob\",\n \"cover_large\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/D161F6375E001A0678A50DBAEEEB3DF66DA88BA5.blob\",\n \"cover_thumb\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/213CBA3128ED7F1E7A86D99882DAD3CAE1974C18.blob\"\n },\n {\n \"_id\": \"59131cad-d18a-490b-867d-d96eab32d3d9\",\n \"type\": \"catalog\",\n \"name\": \"Entertainment & Living Room\",\n \"_attachments\": {\n \"cover\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/86BFC55780E833B7FC2DCF33AB7E7FD323C5E481.blob\",\n \"stub\": true,\n \"revpos\": 2,\n \"length\": 206399,\n \"digest\": \"sha1-hr/FV4DoM7f8Lc8zq35/0yPF5IE=\"\n },\n \"cover_large\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/AFFA90431E5CFEBAAAE7E2DA24901F0E39B3A165.blob\",\n \"stub\": true,\n \"revpos\": 4,\n \"length\": 59400,\n \"digest\": \"sha1-r/qQQx5c/rqq5+LaJJAfDjmzoWU=\"\n },\n \"cover_thumb\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/9303BE494C2AD06698D3D340F032F3EA5800485F.blob\",\n \"stub\": true,\n \"revpos\": 3,\n \"length\": 19193,\n \"digest\": \"sha1-kwO+SUwq0GaY09NA8DLz6lgASF8=\"\n }\n },\n \"_rev\": \"4-bfef06c7534d9abf177bc196c85392f4\",\n \"publishDate\": \"2012-12-10T23:00:00\",\n \"catalogType\": \"General\",\n \"expirationDate\": \"9998-11-30T23:00:00\",\n \"creationDate\": \"2012-12-10T23:00:00\",\n \"sections\": [\n \"07d6ce51-cd4c-4746-af94-2438b9789d54\",\n \"13333eba-b28c-44d4-a98b-afe3ca8562fa\",\n \"3b1bd3a4-8aef-4795-b87a-8619842e0525\",\n \"4eead07a-63a4-4c08-9fcc-cfb6a6d0f88e\",\n \"5b225121-6def-4125-970b-8517d70ffedd\",\n \"6db4df69-eb4e-4d2d-a60c-3e0111c26b79\",\n \"7e8345f3-6d07-44e1-8349-10092d90487a\",\n \"7f380582-b6cb-40f3-b146-e8e74e7aeba7\",\n \"878c32d2-6fec-477d-8e8a-d9f0f17acf46\",\n \"9f436e68-6df6-42dd-a3b8-021e7e434cb7\",\n \"c03d8926-9942-44ad-aefe-7d099213d150\",\n \"e087ac3d-83c3-498b-9d21-09013f64706e\",\n \"ee4fd7d1-812f-47b0-93f9-28a6d80d2185\"\n ],\n \"creator\": \"admin\",\n \"cover\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/86BFC55780E833B7FC2DCF33AB7E7FD323C5E481.blob\",\n \"cover_large\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/AFFA90431E5CFEBAAAE7E2DA24901F0E39B3A165.blob\",\n \"cover_thumb\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/9303BE494C2AD06698D3D340F032F3EA5800485F.blob\"\n },\n {\n \"_id\": \"861320f5-71ab-4a51-9454-cf96b6a02605\",\n \"type\": \"catalog\",\n \"name\": \"Home Office\",\n \"_attachments\": {\n \"cover\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/3AA43EA4411F5431775B0B1222F05EBE796A916B.blob\",\n \"stub\": true,\n \"revpos\": 2,\n \"length\": 317038,\n \"digest\": \"sha1-OqQ+pEEfVDF3WwsSIvBevnlqkWs=\"\n },\n \"cover_large\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/67CAF17693E8F55D67379FA3DD6D9107BEC04DF1.blob\",\n \"stub\": true,\n \"revpos\": 4,\n \"length\": 82130,\n \"digest\": \"sha1-Z8rxdpPo9V1nN5+j3W2RB77ATfE=\"\n },\n \"cover_thumb\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/3C2110A3705D6EF81E9919C49A2061E85E4F0696.blob\",\n \"stub\": true,\n \"revpos\": 3,\n \"length\": 24599,\n \"digest\": \"sha1-PCEQo3BdbvgemRnEmiBh6F5PBpY=\"\n }\n },\n \"_rev\": \"4-fc6b4865c139959c80f9224469a8f355\",\n \"publishDate\": \"2013-01-23T23:00:00\",\n \"catalogType\": \"General\",\n \"expirationDate\": \"9998-11-30T23:00:00\",\n \"creationDate\": \"2013-01-23T23:00:00\",\n \"sections\": [\n \"0c5656f1-dd94-4884-88e9-7eff97eb7bcf\",\n \"3a97c5e6-7113-4152-ba7d-2808809d9d79\",\n \"44f5646a-4219-47be-bcde-470be9b727d1\",\n \"56bbdb2c-bb71-4980-b2e0-244b568498a3\",\n \"6535a941-e95e-40aa-b02c-ab960cf827ef\",\n \"7960ada5-c997-45b6-bd5e-ac3035d2f776\",\n \"8a060e07-1bee-40be-85a2-b28e00753c25\",\n \"9166e442-8e0c-4724-87c3-771121801ae2\",\n \"ab6f025c-c149-457e-af62-191a0dce1c07\",\n \"bd2527cc-1123-4c97-8098-e9625efff3d8\",\n \"c63fe61c-c2a2-4f24-acfd-dafed3c545ed\",\n \"d9970a88-9480-444e-bd0a-9e7a224c00d6\"\n ],\n \"creator\": \"admin\",\n \"cover\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/3AA43EA4411F5431775B0B1222F05EBE796A916B.blob\",\n \"cover_large\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/67CAF17693E8F55D67379FA3DD6D9107BEC04DF1.blob\",\n \"cover_thumb\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/3C2110A3705D6EF81E9919C49A2061E85E4F0696.blob\"\n },\n {\n \"catalogType\": \"General\",\n \"publishDate\": \"2012-07-20T00:00:00\",\n \"creationDate\": \"2012-07-20T15:36:51.557\",\n \"type\": \"catalog\",\n \"sections\": [\n \"75ef4ab4-20d3-4f21-9538-bcbea6778d87\"\n ],\n \"_id\": \"9fd8f423-cd30-4a32-92b7-cc2c3f3457ea\",\n \"creator\": \"tomg\",\n \"_rev\": \"2-089e1f137b94047bb28b73465137cce6\",\n \"expirationDate\": \"9998-01-12T00:00:00\",\n \"darkbackground\": true,\n \"name\": \"test\",\n \"_attachments\": {\n \"cover\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/DA39A3EE5E6B4B0D3255BFEF95601890AFD80709.blob\",\n \"stub\": true,\n \"revpos\": 2,\n \"length\": 0,\n \"digest\": \"sha1-2jmj7l5rSw0yVb/vlWAYkK/YBwk=\"\n }\n },\n \"cover\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/DA39A3EE5E6B4B0D3255BFEF95601890AFD80709.blob\"\n },\n {\n \"catalogType\": \"General\",\n \"publishDate\": \"2012-03-09T00:00:00\",\n \"creationDate\": \"2012-03-09T08:50:51.37\",\n \"type\": \"catalog\",\n \"sections\": [\n \"ebe8fc6c-8edc-45ee-b0f2-4e675932ddb5\"\n ],\n \"_id\": \"c119dc0a-93d7-4b69-800e-c4ff9fa8b8b2\",\n \"creator\": \"00157\",\n \"_rev\": \"2-0cf16353fbcfd7aeef6aea994eb77a0f\",\n \"expirationDate\": \"9998-12-01T00:00:00\",\n \"darkbackground\": true,\n \"name\": \"test\",\n \"_attachments\": {\n \"cover\": {\n \"content_type\": \"image/jpeg\",\n \"file_path\": \"/Users/jmoretti/Library/Application Support/iPhone Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application Support/TouchDB/catalogs attachments/DA39A3EE5E6B4B0D3255BFEF95601890AFD80709.blob\",\n \"stub\": true,\n \"revpos\": 2,\n \"length\": 0,\n \"digest\": \"sha1-2jmj7l5rSw0yVb/vlWAYkK/YBwk=\"\n }\n },\n \"cover\": \"file://localhost/Users/jmoretti/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/720BE27B-11D8-44F7-8895-1A2A2266FF2E/Library/Application%20Support/TouchDB/catalogs%20attachments/DA39A3EE5E6B4B0D3255BFEF95601890AFD80709.blob\"\n }\n]\n{code}", "updateAuthor": { "name": "jmoretti", "key": "jmoretti", "displayName": "Joe Moretti", "active": true, "timeZone": "America/Chicago" }, "created": "2013-05-14T16:38:23.000+0000", "updated": "2013-05-14T16:38:23.000+0000" }, { "id": "251820", "author": { "name": "jmoretti", "key": "jmoretti", "displayName": "Joe Moretti", "active": true, "timeZone": "America/Chicago" }, "body": "Reviewing the persistance adapter in use (code below), I do see that idAttribute appears to be set in the module.exports.afterModelCreate function.\n\n{code:js}\n/**\n * Persistence adapter for TiTouchDB\n */\n\nvar _ = require('alloy/underscore'),\n server = require('com.obscure.titouchdb'),\n db,\n modelname;\n\n\n/**\n * Run arbitrary views from this model's design document\n * @param {Object} name\n * @param {Object} options\n */\nfunction query_view(db, design_doc, name, options) {\n var opts = options || {};\n \n if (OS_IOS) {\n \t// temporary fix to get the lastest version on IOS\n \tdb.clearDocumentCache();\n }\n \n var ddoc = db.designDocumentWithName(design_doc);\n var query = ddoc.queryViewNamed(name);\n if (!query) {\n var err = String.format('invalid view name: %s/%s', design_doc, name);\n Ti.API.log(err);\n if (opts.error) {\n opts.error(null, err);\n }\n return null;\n }\n \n if (_.isBoolean(opts.prefetch)) { query.prefetch = opts.prefetch; }\n if (_.isFinite(opts.limit)) { query.limit = opts.limit; }\n if (_.isFinite(opts.skip)) { query.skip = opts.skip; }\n if (_.isBoolean(opts.descending)) { query.descending = opts.descending; }\n if (_.isFinite(opts.groupLevel)) { query.groupLevel = opts.groupLevel; }\n \n return query;\n}\n\n\nfunction InitAdapter(config) {\n\tTi.API.info('titouchdb InitAdapter:config: ' + JSON.stringify(config));\n if (!config || !config.adapter) {\n Ti.API.error('missing adapter configuration');\n return;\n }\n \n if (!_.isString(config.adapter.dbname) || config.adapter.dbname.length < 1) {\n Ti.API.error('Missing required adapter configuration property: dbname');\n }\n \n if (!_.isString(config.adapter.collection_name) || config.adapter.collection_name.length < 1) {\n Ti.API.error('Missing required adapter configuration property: collection_name');\n }\n \n db = server.databaseNamed(config.adapter.dbname);\n db.ensureCreated();\n\n // register views\n var ddoc = db.designDocumentWithName(config.adapter.collection_name);\n _.each(config.adapter.views, function(view) {\n ddoc.defineView(view.name, view.map, view.reduce);\n Ti.API.info(\"defined \"+view.name);\n });\n\n ddoc.saveChanges();\n\n return {};\n}\n\n\nfunction Sync(method, model, options) {\n var opts = options || {};\n Ti.API.info('titouchdb Sync:');\n Ti.API.info(' method: ' + method);\n Ti.API.info(' options: ' + JSON.stringify(options));\n \n switch (method) {\n case 'create':\n\t var attachments = {};\n\t for (var key in model.attributes){\n \t // if (Object.prototype.toString.call(model.attributes[key]) == '[object Object]' && model.attributes[key].toString() == '[object TiBlob]'){\n \t if (model.attributes[key].toString() == '[object TiBlob]'){\n \t \t attachments[key] = model.attributes[key];\n\t\t\t delete model.attributes[key];\n \t }\n }\n var props = model.toJSON();\n props.modelname = model.config.adapter.modelname;\n var doc = db.untitledDocument();\n doc.putProperties(props);\n for (var key in attachments){\n \t Ti.API.info('adding attachment ' + key + ' with mime type ' + attachments[key].getMimeType());\n \t attachment = doc.currentRevision.createAttachment(key, attachments[key].getMimeType());\n\t\t attachment.body = attachments[key];\n\t }\n model.trigger('create');\n break;\n\n case 'read':\n if (opts.parse) {\n var collection = model; // just to clear things up \n \n // collection\n var ddoc = collection.config.adapter.collection_name;\n var view = opts.view || collection.config.adapter.views[0];\n \n // add default view options from model\n opts = _.defaults(opts, collection.config.adapter.view_options);\n var query = query_view(db, ddoc, view, opts);\n if (!query) {\n break;\n }\n \n var rows = query.rows();\n\n // do not use Collection methods!\n var len = 0;\n if (!opts.add) {\n collection.models = [];\n }\n while (row = rows.nextRow()) {\n var m = collection.map_row(collection.model, row);\n if (m) {\n collection.models.push(m);\n ++len;\n }\n }\n Ti.API.info('inside sync, after query, collection: ' + JSON.stringify(collection));\n collection.view = view;\n collection.length = len;\n collection.trigger('fetch');\n }\n else {\n // object\n var doc = db.documentWithID(model.id)\n model.set(doc.properties);\n model = model.map_doc(model, doc);\n model.id = doc.documentID;\n model.trigger('fetch');\n Ti.API.info('inside sync, read, model: ' + JSON.stringify(model));\n }\n break;\n\n case 'update':\n var attachments = {};\n var doc = db.documentWithID(model.id);\n for (var key in model.attributes){\n \t// if (Object.prototype.toString.call(model.attributes[key]) == '[object Object]' && model.attributes[key].toString() == '[object TiBlob]'){\n \tif (model.attributes[key].toString() == '[object TiBlob]'){\n \t\tattachments[key] = model.attributes[key];\n\t\t\tdelete model.attributes[key];\n \t}\n }\n doc.putProperties(model.toJSON());\n for (var key in attachments){\n \tTi.API.info('adding attachment ' + key + ' with mime type ' + attachments[key].getMimeType());\n \tattachment = doc.currentRevision.createAttachment(key, attachments[key].getMimeType());\n\t\tattachment.body = attachments[key];\n\t }\n model.trigger('update');\n break;\n \n case 'delete':\n if (model.id) {\n var doc = db.documentWithID(model.id);\n doc.deleteDocument();\n model.id = null;\n model.trigger('destroy');\n }\n break;\n } \n}\n\nmodule.exports.sync = Sync;\n\nmodule.exports.beforeModelCreate = function(config) {\n config = config || {};\n \n InitAdapter(config);\n\n return config;\n};\n\nmodule.exports.afterModelCreate = function(Model) {\n Model = Model || {};\n \n Model.prototype.idAttribute = '_id'; // true for all TouchDB documents\n Model.prototype.config.Model = Model; // needed for fetch operations to initialize the collection from persistent store\n \n return Model;\n};\n{code}", "updateAuthor": { "name": "jmoretti", "key": "jmoretti", "displayName": "Joe Moretti", "active": true, "timeZone": "America/Chicago" }, "created": "2013-05-14T16:53:31.000+0000", "updated": "2013-05-14T16:53:31.000+0000" }, { "id": "251832", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "right, Backbone.Collection.get() relies on the idAttribute, in this case {{_id}}. You are storing your ids in the wrong field, since you are referencing {{id}}. So in any case in your model where you are directly referencing {{model.id}} you should probably be using {{model._id}}. The safest way actually would be to use the model's own idAttribute as the key, so perhaps you should change those direct references to {{model.id}} to be {{model[model.idAttribute]}}.", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-05-14T17:17:30.000+0000", "updated": "2013-05-14T17:17:30.000+0000" }, { "id": "251902", "author": { "name": "jmoretti", "key": "jmoretti", "displayName": "Joe Moretti", "active": true, "timeZone": "America/Chicago" }, "body": "That did not correct my issue; however, it seems that Backbone was not adding the models to the _byId hash table which is used by the Backbone.Collection.get() method. I was able to work around it in my sync adopter by adding a line of code to the snippet below from the sync adapter:\r\n{code:js}\r\nvar len = 0;\r\nif (!opts.add) {\r\n\tcollection.models = [];\r\n}\r\nwhile (row = rows.nextRow()) {\r\n\tvar m = collection.map_row(collection.model, row);\r\n\tif (m) {\r\n\t\tcollection._byId[m.id] = m; // <-- this adds the the model to the collection's byId hash table\r\n\t\tcollection.models.push(m);\r\n\t\t++len;\r\n\t}\r\n}\r\n{code}\r\n\r\nI would haves suspected that Backbone.js and ergo Alloy would have handled this (it looks like it is handeld in the Backbone.Collection.add() method). It appearsBackbone is using idAttribute to set Model.id appropriately.", "updateAuthor": { "name": "jmoretti", "key": "jmoretti", "displayName": "Joe Moretti", "active": true, "timeZone": "America/Chicago" }, "created": "2013-05-14T21:02:43.000+0000", "updated": "2013-05-14T21:08:25.000+0000" }, { "id": "251916", "author": { "name": "jmoretti", "key": "jmoretti", "displayName": "Joe Moretti", "active": true, "timeZone": "America/Chicago" }, "body": "Ok, forgive me, I didn't write this sync adapter, so I am reverse engineering it as I dig into this. It appears that models were being added to the collection by the array.push() method directly into the Collection.models array. Looking at this previously (the same snippet from my previous comment), I had always read this as collection.push(m); After correcting this code to use the Backbone.Collection.push() method, all is working as expected.\n\nI apologize again for posting this in the wrong forum and appreciate your help. I will make certain to get a pull request in with this change to the owner of the sync adapter github repo.", "updateAuthor": { "name": "jmoretti", "key": "jmoretti", "displayName": "Joe Moretti", "active": true, "timeZone": "America/Chicago" }, "created": "2013-05-14T21:34:48.000+0000", "updated": "2013-05-14T21:34:48.000+0000" } ], "maxResults": 8, "total": 8, "startAt": 0 } } }