I'm creating the "Discussions" module of my website with AngularJS.
I've actually two types of resources for client<->server communication :
- Discussion $resource (used to retrieve Discussion-related infos, like 'title', 'status', etc. Discussions also contain an array of Message.
- Message $resource
The problem : When I load the page, I do a Discussion.query(), for retrieving discussion title, etc. In order to economize client<->server requests, the messages of the discussion are also returned (in addition to Discussion info). Well, that's great, but what if I want to edit or delete messages ? As I got them using "Discussion" model object, messages are not considered as $resource Message and I can't $update them or *$delete them.
Actually, I could just do a "Messages.get()" for getting real Messages $resources, but it would cost a new request to my server (latency, SQL query, ...).
Currently, I found two workarounds for achieving that :
- Using Message $resource static methods (Message.delete(...), etc)
- "Raw" $http requests
I'm not satisfied by these two solutions, because I want a code as simple as possible.
--
Is it possible to tell to Angular "hey this object is actually a Message $resource !" when I retrieve messages using another resource ? Sorry for strange explanations. I don't think any code would help, but ask me I needed.