Last active
August 29, 2015 14:27
-
-
Save thebigredgeek/f2eec368e59a2dbfb27b to your computer and use it in GitHub Desktop.
DS#loadRelations not working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('console').factory('Employer', function(DS, $rootScope){ | |
var store = DS.defineResource({ | |
name: 'Employer', | |
idAttribute: 'guid', | |
endpoint: '/employers', | |
keepChangeHistory: true, | |
schema: { | |
name: 'string', | |
total_employees: 'number' | |
}, | |
hasMany: { | |
'EmployerDirector': { | |
localField: 'employerDirectors', | |
foreignKey: 'employer_guid' | |
} | |
} | |
}); | |
$rootScope.$on('$unauthorized', function(){ | |
store.ejectAll(); | |
}); | |
return store; | |
}).run(['Employer', angular.noop]); | |
angular.module('console').factory('EmployerDirector', function(DS, $rootScope){ | |
var store = DS.defineResource({ | |
name: 'EmployerDirector', | |
idAttribute: 'guid', | |
endpoint: '/employer_directors', | |
keepChangeHistory: true, | |
schema: { | |
employer_guid: 'string', | |
director_guid: 'string', | |
}, | |
relations: { | |
hasOne: { | |
'Director': { | |
localField: 'director', | |
localKey: 'director_guid' | |
} | |
}, | |
belongsTo: { | |
'Employer': { | |
localField: 'employer', | |
localKey: 'employer_guid', | |
parent: true | |
} | |
} | |
} | |
}); | |
$rootScope.$on('$unauthorized', function(){ | |
store.ejectAll(); | |
}); | |
return store; | |
}).run(['EmployerDirector', angular.noop]); | |
angular.module('console').factory('ResolveEmployers', function(Employer, EmployerDirector, $q, $rootScope){ | |
return function () { | |
return ( | |
Employer.getAll().length ? | |
$q.when(Employer.getAll()) : | |
Employer.findAll() | |
) | |
.then(function(employers){ | |
if (employers.length) { | |
return $q.all((employers || []).map(function(employer){ | |
console.log(employer.guid); | |
return $q.when(Employer.loadRelations(employer.guid)); | |
})); | |
} else { | |
return $q.reject(); | |
} | |
}); | |
}; | |
}); | |
angular.module('console').run(function(ResolveEmployers){ResolveEmployers();}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment