I am in the process of developing the "Discussions" feature for my website using AngularJS.
Currently, I have two types of resources available for client-server communication:
- Discussion $resource (used to fetch Discussion-related information such as 'title', 'status', etc. Discussions also include an array of Messages).
- Message $resource
The issue at hand: Upon loading the page, I perform a Discussion.query() to retrieve discussion titles and other details. To optimize client-server requests, the messages within the discussion are also returned along with the Discussion information. While this is beneficial, it poses a challenge when trying to edit or delete messages. Since the messages were obtained through the "Discussion" model object, they do not function as $resource Messages, thus making it impossible to $update or *$delete them.
One solution could be to simply use "Messages.get()" to obtain actual Message $resources. However, this would require a new request to the server which comes with latency issues and additional SQL queries.
At present, I have identified two workarounds:
- Utilizing static methods of Message $resource (Message.delete(...), etc)
- Direct "Raw" $http requests
Neither of these solutions seem ideal as I am aiming for simplicity in the code implementation.
--
Is there a way to instruct Angular to recognize that an object is actually a Message $resource when retrieving messages using another resource? Apologies for the convoluted explanations. Let me know if further clarification is needed.