Titanium JIRA Archive
Alloy (ALOY)

[ALOY-679] Defaults for pre sqlite file

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionWon't Fix
Resolution Date2014-03-12T18:12:28.000+0000
Affected Version/sn/a
Fix Version/s2014 Sprint 05
ComponentsModels
LabelsAlloy
ReporterNavid Ghahramani
AssigneeUnknown
Created2013-05-28T16:26:48.000+0000
Updated2018-03-07T22:26:01.000+0000

Description

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;
    }
};

Comments

  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