Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Cannot read Alloy Model Property

$
0
0

I am trying to read a property from a saved model using the SQL adapter. I want to query the collection, retrieve the first (and only) result, and access a property on that model. I cannot seem to access the property even though the JSON.stringify() shows the property as being populated.

var images = Alloy.createCollection('image');
    var table = images.config.adapter.collection_name;
    var query = 'SELECT * from ' + table + ' where outfit_id="' + args.outfit_id + '"';
    images.fetch({query: query});
 
    alert(JSON.stringify(images.at(0)));
    alert(images.at(0).image_path);
 
    $.firstOutfit.image = images.at(0).image_path;
As I mentioned, the first alert shows a fully populated model containing an "image_path" property. However, the second alert is completely empty. Any ideas? I am at a complete loss here.

In case it helps, here is the simple Model definition:

exports.definition = {
    config: {
        columns: {
            "outfit_id": "String",
            "image_path": "String"
        },
        adapter: {
            type: "sql",
            collection_name: "images"
        }
    },      
    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;
    }
}

Viewing all articles
Browse latest Browse all 8068

Trending Articles



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