How the save(CRUD) operation is performed in the Restful table? I request someone to help me on this one?

ARUN KUMAR MK
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 3, 2016
 

7 answers

1 accepted

0 votes
Answer accepted
ARUN KUMAR MK
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 5, 2016

I had overridden the save of the backbone.js and passed the value to the attribute and it worked. Below is the code for that save(as well as for the update) operation.

AJS.RestfulTable.EntryModel = Backbone.Model.extend({
    /**
     * Overrides default save handler to only save (send to server) attributes that have changed.
     * Also provides some default error handling.
     *
     * @override
     * @param attributes
     * @param options
     */
    save: function (attributes, options) {
attributes.projectKey = dataProjectKey;
console.log("console 4:",attributes.projectKey);
        options = options || {};

        var instance = this,
            Model,
            syncModel,
            error = options.error, // we override, so store original
            success = options.success;

        // override error handler to provide some defaults
        options.error = function (model, xhr) {

            var data = $.parseJSON(xhr.responseText || xhr.data);

            instance._serverErrorHandler(xhr);

            // call original error handler
            if (error) {
                error.call(instance, instance, data, xhr);
            }
        };

        // if it is a new model, we don't have to worry about updating only changed attributes because they are all new
        if (this.isNew()) {
            // call super
            Backbone.Model.prototype.save.call(this, attributes, options);

        // only go to server if something has changed
        } else if (attributes) {
            // create temporary model
            Model = Backbone.Model.extend({
                url: this.url()
            });
            console.log("Temporary Model is :",Model);


            syncModel = new Model({
                id: this.id
            });

            options.success = function (model, xhr) {

                // update original model with saved attributes
                instance.clear().set(model.toJSON());

                // call original success handler
                if (success) {
                    success.call(instance, instance, xhr);
                }
            };

            // update temporary model with the changed attributes
            syncModel.save(attributes, options);
        }
    }
});

 

0 votes
ARUN KUMAR MK
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 4, 2016

Ok Nic, Thanks for your Reply, i will find the solution and post it here. Thanks for your time.

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 4, 2016

Sorry, I'm still lost.  If it's doing the CRUD for you, what's the problem?  If you need to "hard code" a value, then set it in your code, just don't ask the user for it.

 

0 votes
ARUN KUMAR MK
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 4, 2016

Since it is handling the crud operations automatically, i couldn't find a solution for it. my problem is during save i need to hardcode a value of an column in that table. how to bind the value?

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 4, 2016

Now I'm completely lost. 

You say it's handling it automatically, so there's no problem.  So what is the actual question?

0 votes
ARUN KUMAR MK
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 4, 2016

Hi nic, I am using the one that google points to. Yes it is handling it automatically.

can u help me with this question.https://answers.atlassian.com/questions/38066251

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 3, 2016

You'll need to explain what the Restful table is for most of us.  Although from what I've read (assuming you're using the one google points to) it should handle it automatically.

I think you also need to explain where you are stuck

Suggest an answer

Log in or Sign up to answer