[TIMOB-18308] The Sync method of the sqlite adapter doesn't use the idAttribute
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | SQLite, adapter, alloy, models, sync |
Reporter | Michiel van Eerd |
Assignee | Unknown |
Created | 2015-01-05T10:01:20.000+0000 |
Updated | 2018-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.
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}