Quantcast
Viewing all articles
Browse latest Browse all 8068

Application has exited from iOS7 simulator - after retrieving multiple models or adding multiple models in a collection

Hello I'm working on a mobile titanium app.

I have two models, one for billEvents and one for the persons that belong to billEvents named billEventsPersons.

Now I'm experiencing some weird behavior, it started when I wanted to add persons in a iteration to a model. For example, three persons represent three models that are added to the billEventsPersons collection.

The code for this is:

function fillPersonsForBillEventModel(billEventId) {
    //the collection
    var billEventsPersons = Alloy.Collections.billEventsPersons;
 
    var billEventPerson,//the model for in the collection
        data = {};
 
    //loop through the global persons object which contains our names and amount or persons
    _.each(persons, function(val, index) {
        data = {};
        data['name'] = val.personName;
        data['owesAmount'] = val.personAmount;
        data['paid'] = 'false';
        data['bill_event_id'] = billEventId; //passed in this function
        data['created'] = global.getDateAndTime();
        data['updated'] = global.getDateAndTime();
 
        billEventPerson = Alloy.createModel('billEventsPersons', data);
 
 
        billEventsPersons.add(billEventPerson);
        billEventPerson.save();
 
 
    });
 
    return true;
}
Now if I do not log anything after executing this code it will keep running. But if I DO log something like:

console.log(billEventsPersons)

The app crashes with this log message:

-- End simulator log --------------------------------------------------------- [INFO] : Application has exited from iOS Simulator [INFO] : Project built successfully in 9s 821ms

If I don't log anything and I go to another view where the just added values are read. The app crashes in the same way. If I reboot the app and try to read it again it will just run fine but the added data is gone. So it just returns an empty set of results.

So, some weird inconsistent behaviour.. I will also provide my models and migrations:

models/billEvents.js

exports.definition = {
    config: {
        columns: {
            "id": "INTEGER PRIMARY KEY AUTOINCREMENT",
            "name": "TEXT",
            "euros": "INTEGER",
            "cents": "INTEGER",
            "location": "TEXT",
            "remind_me": "INTEGER",
            "expiration_date": "TEXT",
            "image_url": "TEXT",
            "fully_paid": "TEXT",
            "created": "TEXT",
            "updated": "TEXT",
        },
 
        adapter: {
            type: "sql",
            collection_name: "billEvents",
            idAttribute: "id",
            db_name: "rekeningdelen",  
        }
    },
    extendModel: function(Model) {
        _.extend(Model.prototype, {
            // extended functions and properties go here
        });
 
        return Model;
    },
    extendCollection: function(Collection) {
        _.extend(Collection.prototype, {
            // extended functions and properties go here
        });
 
        return Collection;
    }
};

migrations/..billEvents.js

migration.up = function(db) {
    db.createTable({
        "columns": {
            "id": "INTEGER PRIMARY KEY AUTOINCREMENT",
            "name": "TEXT",
            "euros": "INTEGER",
            "cents": "INTEGER",
            "location": "TEXT",
            "remind_me": "INTEGER",
            "expiration_date": "TEXT",
            "image_url": "TEXT",
            "fully_paid": "TEXT",
            "created": "TEXT",
            "updated": "TEXT",
        },
        "adapter": {
            "type":"sql",
            "collection_name":"billEvents",
            "db_file": "/rekeningdelen.sqlite",  
            "db_name": "rekeningdelen",  
        }
    });
};
 
migration.down = function(db) {
    db.dropTable("billEvents");
};
models/billEventsPersons.js:
exports.definition = {
    config: {
        columns: {
            "id": "INTEGER PRIMARY KEY AUTOINCREMENT",
            "name": "TEXT",
            "bill_event_id": "INTEGER",
            "owesAmount": "INTEGER",
            "paid": "TEXT",
            "created": "TEXT",
            "updated": "TEXT",
        },
        adapter: {
            type: "sql",
            collection_name: "billEventsPersons",
            idAttribute: "id",
            db_name: "rekeningdelen",  
 
        }
    },
    extendModel: function(Model) {
        _.extend(Model.prototype, {
            // extended functions and properties go here
        });
 
        return Model;
    },
    extendCollection: function(Collection) {
        _.extend(Collection.prototype, {
            // extended functions and properties go here
        });
 
        return Collection;
    }
};
migrations/..bilEventsPersons.js:
migration.up = function(db) {
    db.createTable({
        "columns": {
            "id": "INTEGER PRIMARY KEY AUTOINCREMENT",
            "name": "TEXT",
            "bill_event_id": "INTEGER",
            "owesAmount": "INTEGER",
            "paid": "TEXT",
            "created": "TEXT",
            "updated": "TEXT",
 
        },
 
        "adapter": {
            "type":"sql",
            "collection_name":"billEventsPersons",
            "db_file": "/rekeningdelen.sqlite",  
            "db_name": "rekeningdelen",  
        }
 
    });
};
 
migration.down = function(db) {
    db.dropTable("billEventsPersons");
};
Well I hope all of this makes sense to someone,

Thanks in advance


Viewing all articles
Browse latest Browse all 8068

Trending Articles