I ran into this a while back and it was doing my head in.
Could it be that a ‘Moralis.Cloud.beforeSave’ in Cloud Functions is not triggered when adding tables through a sync job (plugin)?
When I run the beforeSave just using the web3 UI it works.
When I delete all the tables and manually run the Sync job to create new tables, beforeSave did not run to add the additional user and token fields:
// link sale and item data Polygon
Moralis.Cloud.beforeSave("ItemsForSalePolygon", async (request) => {
const query = new Moralis.Query("PolygonNFTOwners")
query.equalTo("token_address", request.object.get('tokenAddress'))
query.equalTo("token_id", request.object.get('tokenId'))
const object = await query.first()
if (object){
const owner = object.attributes.owner_of
const userQuery = new Moralis.Query(Moralis.User)
userQuery.equalTo("accounts", owner)
const userObject = await userQuery.first({useMasterKey:true})
if (userObject){
request.object.set('user', userObject);
}
request.object.set('token', object);
}
})
Or is the sync job cached somehow?