Closed
Description
When I do this:
var User = DS.definitions['user'][DS.definitions['user'].class];
DS.findAll('user', {}).then(function(users) {
console.log(users[0] instanceof User); // <-- logs "false"
console.log(DS.get('user', 1) instanceof User); // <-- logs "true"
});
I would expect that the objects returned from findAll are also instances of the user. Here's how I'm using it:
// ... some state definitions
$stateProvider.state('root.auth.home.locks.list', {
url: '',
templateUrl: homeTemplateRoot + 'Locks/LocksCtrl.html',
controller: 'LocksCtrl',
resolve: {
locks: resolveDS('findAll', ['lock', {}]),
users: resolveDS('findAll', ['user', {}])
}
});
// ... other state definitions
function resolveDS(method, args) {
if (!_.isArray(args)) {
args = [args];
}
return function(DS) {
return DS[method].apply(DS, args);
};
}
// in my LocksCtrl
angular.module('pk.web').controller('LocksCtrl', function ($scope, locks, users, _) {
// some $scope initialization stuff using the injected users.
});
To be able to get the returned objects as an instance of a User, I would have to do DS.get for everything. If that's the way I'm supposed to be using this and I'm not supposed to actually inject the results of the call to findAll
then that's fine. Though I would prefer to simply do it as I am because it seems to make sense to me this way.