[ALOY-705] Add possibility to read a Model by its ID in the SQLite sync adapter
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | n/a |
Status | Resolved |
Resolution | Duplicate |
Resolution Date | 2014-01-20T22:10:23.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Models, Titanium SDK |
Labels | n/a |
Reporter | Shak Hossain |
Assignee | Unknown |
Created | 2013-06-12T20:21:56.000+0000 |
Updated | 2018-03-07T22:25:51.000+0000 |
Description
Unfortunately it is currently not possible to read a single Model via the SQL sync adapter, only to read the whole table/collection.
In the official Backbone sync adapter it is possible to read an object by its ID:
var mode = Alloy.createModel('Tony', {
id: '121'
});
model.fetch();
A simple fix is possible afaik:
/lib/alloy/sync/sql.js, line 200
var sql;
// If a query is provided
if(opts.query)
sql = opts.query;
// If we are fetching a single Model
else if (model.id)
sql = {
statement: "SELECT * FROM " + table + " WHERE " + model.idAttribute + " = ?",
params: model.id
};
// If we are fetching a Collection
else
sql = "SELECT * FROM " + table;
Moving this to Alloy team for feature implementation.
I believe this is a duplicate of ALOY-829, but can re-open if it does not cover the exact case discussed here.