Models, commit, and method:POST

edited October 2013 in Enyo 2.4
I'm trying to do a commit using the POST method. Something like:

		var params = {"source": source,  
					"sourceIdType": sourceType, "fileURL":fileURL, 
					"articleid": articleid};

		var newURL = new Search.ArticleUrlModel(params);
		newURL.commit({postBody:params, method:"POST"});
Unfortunately, it keeps doing a PUT. Any thoughts on how to get it to do a commit? Or should overload the method?

Thanks,
Cage

Comments

  • edited August 2013
    It looks like the current enyo.Source code always uses PUT with a model that's not marked as "isNew". I think that code should respect the method in the options block if it's provided... looks like a bug to me.

    Filed as https://enyojs.atlassian.net/browse/ENYO-3000
  • I had the same case. The problem is that the POST method is called when the model "isNew" flag is set to true. The "isNew" is true on the early stage of model construction and If you're calling the enyo.Model constructor with params the "isNew" will be false after the call. I've added my own flag which indicates if the commit() was successfuly called before and if my flag is false I'm setting the enyo.Model.isNew to true manualy.
    I'm not sure if it's the best approach but It's works for me.
    I think that enyo.Model constructor should always leave "isNew" as true even if the constructor was called with params.
  • edited August 2013
    Hmm, so setting isNew=true seems to get it to do a post. However, the variables are not making it through to server. Any thoughts, either on how to solve problem or how to debug? Thanks.
  • Cole closed out ENYO-3000 as "working as intended"... he recommended making your own derived enyo.Source kind to implement your own storage mechanism.
  • Uhm, okay. I thought POST/PUT was standard functionality for RESTful mechanism and enyo's models/collections were to implement this? I wasn't implementing a proprietary storage system - just utilizing a server that expects a POST per standard REST definition.

    I ended up just using enyo.Ajax, which works fine. But seems like a major oversight if enyo.Model doesn't handle this natively...
  • I would agree with psarin and your earlier comment Ben. The options block should override, and a POST should be used over a PUT.

    In theory, a PUT is more accurate, however not everything honors PUT. Particularly:
    1) IE in particular doesn't like PUT on IE8 and IE9.
    2) We have no control over the endpoint of a CORS request to other servers. All servers will support a POST verb but we can't guarantee that they will support a PUT.

    Just my 2 cetns.
Sign In or Register to comment.