How should I represent many-to-many class and professor relationship using a REST API and Zend Framework? -
i'm developing rest api using zend framework 1.12.3.
i've got 3 different resources: classes, subjects , professors. each class may have assigned multiple subjects, , each subject may have assigned 1 or multiple professors.
the schema this:
classes: class: id: 123 name: foo subjects: subject: id: 14 name: chemistry professors: professor: id: 741 name: jeremy clarkson professor: id: 963 name: richard hammond subject: id: 16 name: physics professors: professor: id: 753 name: james may
i wondering best approach list subjects , professors, both assigned , unassigned (on page actual assignment going take place).
should return assigned subjects , professors, , cross-reference id array containing subjects , professors?
or should return array containing subjects , professors, each having "assigned" variable set 0 or 1?
in other apis i've seen dealing assigned users projects done using first method (the api returns ids of assigned users, , client application cross-references ids array containing users). best practice regarding assignments ?
i suggest former method since data set required display concise list of subject/professors small compared latter method. if you're not doing already, i'd recommend using json data format. makes easy call method client-side js , create interesting representations.
based on initial list of subject/professor hierarchy easy match ids full set call suggest, or make call each professor id in set , details individual. if you're doing them via ajax, can run them in parallel: parallel asynchronous ajax requests using jquery
Comments
Post a Comment