Titanium JIRA Archive
Alloy (ALOY)

[ALOY-679] Defaults for pre sqlite file

GitHub Issuen/a
ResolutionWon't Fix
Resolution Date2014-03-12T18:12:28.000+0000
Affected Version/sn/a
Fix Version/s2014 Sprint 05
ReporterNavid Ghahramani


Hi, I want to know how possible set defaults on Model config definition that use pre sqlite file without set to sqlite file I set to model config like this but it's not working this is my config:
exports.definition = {
    config: {
        "adapter": {
            "type": "sql",
            "collection_name": "product",
            "db_file": "/db.sqlite",
            "idAttribute": "id",
            "remoteBackup": false
        "defaults": {
            "image": "/images/defaultProduct.png"
    extendModel: function (Model) {
        _.extend(Model.prototype, {
        // end extend
        return Model;
    extendCollection: function (Collection) {
        _.extend(Collection.prototype, {
        // end extend
        return Collection;


  1. Carter Lathrop 2013-05-30

    Navid, Questions or concerns about coding practices or how to do X are not considered bugs and belong in the QA community boards. The Titanium Community Jira is a place to log known bugs or issues with the platform/SDK. Please direct your question to the boards here: https://developer.appcelerator.com/questions/newest Regards, Carter
  2. Tony Lukasavage 2013-05-30

    [~clathrop] the issue originated from a Q&A question and I asked Navid to add his case here.
  3. Navid Ghahramani 2013-05-30

    Please Tony add to this issue for support SQLite file defaults while inserting. Refer to: [Defaults on sqlite file](http://developer.appcelerator.com/question/153006/defaults-value-does-not-working)
  4. Tim Poulsen 2014-03-12

    In my tests, extending the model like this works:
       extendModel : function(Model) {
         _.extend(Model.prototype, {
           validate: function (attrs) {
             for (var key in attrs) {
               var value = attrs[key];
               if (key === "image") {
                 if (value.length === 0) {
                   // no image value set
                   attrs[key] = '/images/defaultProduct.png';
                   Model.prototype.save.call(this, attrs);
         // end extend
         return Model;
  5. Tim Poulsen 2014-03-12

    Closing as won't fix because there's a workable method to accomplish the desired outcome without making Alloy changes.

JSON Source