Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18308] The Sync method of the sqlite adapter doesn't use the idAttribute

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
LabelsSQLite, adapter, alloy, models, sync
ReporterMichiel van Eerd
AssigneeUnknown
Created2015-01-05T10:01:20.000+0000
Updated2018-02-28T19:55:05.000+0000

Description

The Sync method uses model.idAttribute instead of model.config.adapter.idAttribute making fetch with an id go wrong. For example the following model: {noformat} exports.definition = { config: { columns: { "order_id": "INTEGER PRIMARY KEY AUTOINCREMENT", "title": "TEXT", "created_at": "INTEGER", "price": "INTEGER" }, adapter: { type: "sql", collection_name: "Orders", idAttribute : "order_id" } }, // other keys } {noformat} Now if we do a fetch on a specifc id: {noformat} var orders = Alloy.createCollection("Order"); orders.fetch({ id : 2, success : function() { console.log("OK"); } } ); {noformat} We get an error "no such column: alloy_id" because the sync adapter didn't use the model.config.adapter.idAttribute, but model.idAttribute that returned undefined so it used the default alloy id.

Comments

  1. Michiel van Eerd 2015-01-12

    There are 2 things you can do to circumvent this as long as this isn't fixed: 1) Copy the sql.js sync adapter, rename it, edit it (change "model.idAttribute" to "model.config.adapter.idAttribute") and use this as your sync adapter. 2) Add the idAttribute to the object that extends the collection: {noformat} exports.definition = { config: { }, extendCollection: function(Collection) { _.extend(Collection.prototype, { idAttribute : "my_id" } } {noformat}

JSON Source