How to duplicate a row (exact copy of data with new ObjectId) in Parse?

I am working on web application with node.js and parse.com. I have an Object BoatDay in Parse. In application, when a button is clicked it should duplicate an BoatDay with new ObjectId.

Until now, what I have done is;
I made an array of boatDay in view boatday:{}; Then on click event to the button, I tried this;

restoreBoatDay: function(event) {
        event.preventDefault();
        var self = this;
        var e = $(event.currentTarget);
        var boatdayId = e.closest('.my-boatday').attr('data-id');
        console.log(self.boatday[boatdayId]);
    },

When I console to console.log(boatdayId); it gives me right objectId of BoatDay. But when I console to console.log(self.boatday[boatdayId]); it gives me undefined. Why?

Again I tried different way to duplicate the BoatDay this way;

restoreBoatDay: function(event) {
        event.preventDefault();
        var self = this;
        var e = $(event.currentTarget);
        var boatdayId = e.closest('.my-boatday').attr('data-id');
        // console.log(self.boatday[boatdayId]);

        var query = new Parse.Query(Parse.Object.extend("BoatDay"));
        query.get(boatdayId, {

          success: function(boatDay) {

            new BoatDayModel().save({

                status:'creation', 
                name: boatDay.get('name'), 
                description: boatDay.get('description'),
                date: boatDay.get('date'), 
                departureTime: boatDay.get('departureTime'), 
                arrivalTime: boatDay.get('arrivalTime'),
                duration: boatDay.get('duration'), 
                location: boatDay.get('location'),
                locationText: boatDay.get('availableSeats'), 
                availableSeats: boatDay.get('availableSeats'), 
                price: boatDay.get('price'),
                bookingPolicy: boatDay.get('bookingPolicy') , 
                cancellationPolicy: boatDay.get('cancellationPolicy'), 
                category: boatDay.get('category'), 
                arrivalTime: boatDay.get('arrivalTime')

            }).then(function(){
                self.render();
            });

          },

          error: function(object, error) {
            // The object was not retrieved successfully.
            // error is a Parse.Error with an error code and message.
          }

        });

    },

This does not save to the Parse. I have been trying yesterday could not find the way. Hope I get some help here to figure out what am I doing wrong. Thanks in advance.


Source: javascript

Leave a Reply