0
votes

What is the pattern to access server side business logic with ember data. For example, I have a"markAsFavourite(itemId)" function on my backend API. How can i call this function through ember data, and reload the specified item record after the function is evaluated?

I can make this by hand in the controller, but i dont think its a good idea to split my API access into two places.

Or is there a better way to handle this problem?

2

2 Answers

0
votes

I haven't ever tried to do that before, but the first thing that comes to my mind to avoid splitting your API would be to encapsulate commands to your server in your own custom rolled command object that is posted to the server with your server sending back an appropriate response. Maybe something like:

{ "function":"do_something","target_model":"models","target_ids":[1,2,3,4,5]...etc

I think you could do a lot of interesting things that way...

0
votes

I think you should try to set the item as marked and then commit it to the server. Then let the server need to do want is needed to make it true.

App.Item = DS.Model.extend({
    favourite: DS.attr('boolean')
});

Then the rest full API need to check for it and then update what ever needs to be done to make it marked as favorite.