I'm working on an example Usergrid app with the JavaScript SDK and jQuery
Mobile and I have an update function that looks like this:

            function update() {

                var name = $("#edit-name-field").val();
                var identifier = {
                    name: name,
                    type: "restaurant"
                };

                client.getEntity(identifier, function(err, response) {
                    if (err) {
                        alert("Error getting entity to be updated");

                    } else {

                        // CREATE ENTITY FROM DATA
                        var restaurant = new Usergrid.Entity( {
                            client: client,
                            data: response.getEntities()[0]
                        });

                        var city = $("#edit-city-field").val();
                        restaurant.set("city", city);
                        restaurant.save(function(err) {
                            if (err) {
                                alert("Error updating entity");
                            }
                        });
                        loadList();
                        history.back();
                    }
                });

            }

The above code works for me, but I have a question about it.

It took me a while to figure out that the response.getEntities() method
does not return Entities, instead it returns "data" objects and you must
use those to construct Entities if you want to use Entity methods such as
set() and save().

My question is: why does't getEntities() return Entities? Is this a bug or
am I using the SDK incorrectly in some way.

Thanks,
Dave

Reply via email to