[ALOY-679] Defaults for pre sqlite file
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Won't Fix |
Resolution Date | 2014-03-12T18:12:28.000+0000 |
Affected Version/s | n/a |
Fix Version/s | 2014 Sprint 05 |
Components | Models |
Labels | Alloy |
Reporter | Navid Ghahramani |
Assignee | Unknown |
Created | 2013-05-28T16:26:48.000+0000 |
Updated | 2018-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
- 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
- Tony Lukasavage 2013-05-30 [~clathrop] the issue originated from a Q&A question and I asked Navid to add his case here.
- 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)
- 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; }
- 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.