In my app I have an array of objects, all fields in the object have string values. I need to iterate through the array and save each object to the database. However I do not want all the fields in the object to be saved to the database as strings, I want some to be saved as int, some as boolean, and some as date. I am trying to convert the strings to the desired value before saving to the database. This is working OK for ints, the strings are converted to ints and saved to the database as int values. But I cannot get it to work for boolean or date values. Booleans are being saved to the database as empty strings, dates are being saved as empty unknown type.
Here is the snippet code I am using to convert the string values and save to the database:
function Challenges1(args) {
args = args || {};
this.id = args.id || "";
this.name = args.name || "";
this.sub_category = args.sub_category || "";
this.expiration = args.expiration || "";
this.is_featured = args.is_featured || "";
}
var async = new Backendless.Async(
function( success )
{
response.send( success );
},
function( failure )
{
response.send( failure );
});
for (var i = 0; i < num_challenges; i++) {
var challenge_id_int = parseInt(all_challenges.challenge_id);
var challenge_sub_cat_int = parseInt(all_challenges.challenge_sub_category);
var challenge_is_featured_bool;
if (all_challenges.challenge_is_featured == "TRUE")
{challenge_is_featured_bool = true;}
else
{challenge_is_featured_bool = false;}
var challenge_expiration_date = new Date (all_challenges.challenge_expiraton);
var current_challenge = new Challenges1( {
id: challenge_id_int,
name: all_challenges.challenge_name,
sub_category: challenge_sub_cat_int,
expiration: challenge_expiration_date,
is_featured: challenge_is_featured_bool
});
var abc = Backendless.Persistence.of(Challenges1).save( current_challenge, async );
}
What do I need to do to have the values saved in to the database as Boolean and DateTime types?