Restangularize subresources
Is there a simple way to tell restangular that a certain field is a collection of resources?
For instance in my app I can do:
GET to: /api/courses/123
Restangular.one('courses', 123).get();
/* OR */
GET to: /api/courses/123/students
Restangular.one('courses', 123).all('students').getList();
The first call however, fetches the course with a field students that already contains an array of the students in the course. Is there any way to say: "Restangular, this array is not merely an array of objects, but rather it's a student collection" so that then I can do things like students[0].remove()
Unrelated: Vamos a ganar el mundial o no?
this would be cool!
What about:
Restangular.one('courses', 123).get().then(function (course) {
course.students = Restangular.restangularizeCollection(course, course.students, 'students');
// You should now be able to do 'course.students[0].remove()'
// And if you want to chain promises:
return course;
});
Hi @pauldijou ,
I'm looking for solution for this issue as well. Yours works for most cases, not all.
Two major problem for Restangular.restangularizeCollection
- It always set the
fromServerflag to false. So it breaks the.save()method. - Per #727, it does not define the parent collection correctly.
Any news about that ? Or any way in a tutorial to do this ?
+1
Can a more concrete example be provided for this?