Quantcast
Viewing all articles
Browse latest Browse all 8068

Help, Replace SQL Sintax on model...

Hi everyone, I'm making a mobile system that communicates with my web system. This system registers sales ... This is my model

config: {
        columns: {
            "sale_id"       : "integer",
            "sale_price"    : "real",
            "sale_discount" : "real",
            "sale_date"     : "string"
        },
        adapter: {
            type: "sql",
            collection_name: "Sale",
            idAttribute: "sale_id"
        }
    },
So every sale that is registered by my mobile system it receives a negative sale_id
var objSale = { 
    sale_id: -1,
    sale_price: 150.00,
    sale_discount: 0.5,
    sale_date: "2013-9-8"
};
var modelSale = Alloy.createModel("Sale", objSale);
modelSale.save();
And when I sync this sale to my web system, it processes the real sale_id of that sale. Here begins my problem .. After the sync completed, I return this final sale_id to my mobile system with the intention of changing my sale_id negative. With this code
extendModel: function(Model) {
        _.extend(Model.prototype, {
            // extended functions and properties go here
            syncDone: function(oldID, newID) {
                this.fetch( {"sale_id": oldID} );
                this.set("sale_id", newID);
                // REPLACE INTO Sale(sale_id) VALUES(newID) WHERE sale_id = oldID;
                this.save({"sale_id": oldID});
            }
        });
        return Model;
    },
But it is not working... I need to create something like a syntax
REPLACE INTO Sale(sale_id) VALUES(1) WHERE sale_id = -1;
Want you to give me suggestions of what I'm missing or how it could be done. Got that? Thanks...

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>