xavierlacot / joli.js

joli.js is an Activerecord-like javascript ORM, particularly suited for being used in the Appcelerator Titanium Mobile framework.
MIT License
267 stars 60 forks source link

toArray method not returning anything #25

Closed rlustemberg closed 12 years ago

rlustemberg commented 12 years ago

Hi Xavier: Thanks a lot for the great work. I was working with joli.js , and needed to retrieve the values of a record directly. I suppose we need to use the toArray method. If that's the case I've noticed that you are initializing the return object as an array but assigning string keys to it. As a result the return value is an empty array. Should it not be initialized as an object? toArray: function() { var result = {};

        joli.each(this._options.table.getColumns(), function(colType, colName) {
            result[colName] = this._data[colName];
        }, this);
        return result;
    }

instead of: toArray: function() { var result = [];

        joli.each(this._options.table.getColumns(), function(colType, colName) {
            result[colName] = this._data[colName];
        }, this);
        return result;
    }

I've changed that and I get the desired result (my desired result). Might I be breaking something?

xavierlacot commented 12 years ago

Thanks Richard :-)