Titanium JIRA Archive
Alloy (ALOY)

[ALOY-705] Add possibility to read a Model by its ID in the SQLite sync adapter

GitHub Issuen/a
TypeNew Feature
Priorityn/a
StatusResolved
ResolutionDuplicate
Resolution Date2014-01-20T22:10:23.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsModels, Titanium SDK
Labelsn/a
ReporterShak Hossain
AssigneeUnknown
Created2013-06-12T20:21:56.000+0000
Updated2018-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;

Comments

  1. Shak Hossain 2013-06-13

    Moving this to Alloy team for feature implementation.
  2. Tony Lukasavage 2014-01-20

    I believe this is a duplicate of ALOY-829, but can re-open if it does not cover the exact case discussed here.

JSON Source