Hi, 我想做一个用户收藏産品的效果,現在我有三個tables, _User, products, 和Favourite,然后我就這樣寫

var user = new AV.Object('_User')
            user.set('objectId',value);

            var product = new AV.Object('products');
            product.set('objectId',this.props.navigation.state.params.value.objectId)

            var favTable = new AV.Object('Favourite');

            favTable.set('userId', value);
            favTable.set('productId', this.props.navigation.state.params.value.objectId);

            favTable.save().then(function (callback){
                console.log(callback)

            },function(error){
                console.log('favError: '+ error);
            })

出了error, 說 no password, 但我只想在Favourite 的table save _User 的pointer和products的pointer by objectID 我應該如何處理,謝謝

當用戶收藏了幾個商品,我可以在 Favourite這table find userId然后就看到那個用户收藏的商品

use AV.User.createWithoutData(objectId) to create a User Pointer.

還是不行,在favourite table 没有新增data

 var user =new AV.User.createWithoutData(value);

            var product = new AV.Object('products');
            product.set('objectId',this.props.navigation.state.params.value.objectId)

            var favTable = new AV.Object('Favourite');

            favTable.set('userId', user);
            favTable.set('productId',product);

            favTable.save().then(function (callback){
                console.log(callback)

            },function(error){
                console.log('favError: '+ error);
            })

            
        });

please help sob

 addFavourite() {
        this.getData('userID', value => {


            console.log('UserID: ' + value);

            var user =AV.User.createWithoutData(value);

            
            var product = AV.Object.createWithoutData('products',this.props.navigation.state.params.value.objectId);
          

            var favTable = new AV.Object('Favourite');

            favTable.set('userId', user);
            favTable.set('productId',product);

            favTable.save().then(function (callback){
                console.log(callback)

            },function(error){
                console.log('favError: '+ error);
            })

            
        });

    }

return Error: not found sob

addFavourite() {
        this.getData('userID', value => {


            console.log('UserID: ' + value);

            var user =AV.Object.createWithoutData("_User",value);

            
            var product = AV.Object.createWithoutData('products',this.props.navigation.state.params.value.objectId);
          

            var favTable = new AV.Object('Favourite');

            favTable.set('userId', user);
            favTable.set('productId',product);

            favTable.save().then(function (callback){
                console.log(callback)

            },function(error){
                console.log('favError: '+ error);
            })

            
        });

    }

Yeah, Success!!

1 人赞了这个帖子.