Titanium JIRA Archive
Alloy (ALOY)

[ALOY-487] SQL adapter does not accept ID when using PRIMARY KEY

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionDuplicate
Resolution Date2013-02-09T01:39:51.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.0.0, 2013 Sprint 03
ComponentsRuntime
Labelsalloy
ReporterDavid S
AssigneeTony Lukasavage
Created2013-01-25T15:48:13.000+0000
Updated2014-01-28T23:28:55.000+0000

Description

If a new model is created that uses a 'INTEGER PRIMARY KEY' designation on a custom id field as specified with an idAttribute field in the model adapter section, when a new model is created and the custom id field is provided at creation time it will not be accepted nor added to the database. If custom id field is omitted on model creation, it will insert the model into the database successfully, with an id value one higher than any existing id value that is currently in the database.

Comments

  1. Tony Lukasavage 2013-01-25

    I believe you had a test case or some code to go with this?
  2. David S 2013-01-25

    I have modified the SQL Keywords example to use this model; exports.definition = { config: { "columns": { name: 'TEXT', nickname: 'TEXT', // column values can have types with keywords fighterId: 'INTEGER PRIMARY KEY' }, "adapter": { "type": "sql_new", // The table name inside the sqlite database to use for // models and collections based on this definition. "collection_name": "fighters", // idAttribute tells Alloy/Backbone to use this column in // my table as its unique identifier field. Without // specifying this, Alloy's default behavior is to create // and "alloy_id" field which will uniquely identify your // rows in the table with a text GUID. "idAttribute": "fighterId" } } } I try to add an item with this code which is triggered on the click of the "Fighters" label; function addTestFighter(e) { // create the test fighter model var model = Alloy.createModel('fighters', { name: 'Name ' + counter, nickname: 'Nickname ' + counter, fighterId: counter * 100 }); counter++; // add model to the collection and save it to sqlite fighters.add(model); model.save(); // let's refresh so we can see the ids coming from the // autoincrement field in the sqlite database in the // row click alerts fighters.fetch(); }
  3. David S 2013-02-01

    Tony, any news on this?
  4. Christina Hustedde 2013-02-08

    Watching, because I'm having this issue as well.
  5. Tony Lukasavage 2013-02-09

    This is a duplicate of ALOY-508 and is resolved for 1.0.0

JSON Source