Hey guys,
Iâm currently updating the value from one table after fetching the required value from another table. This is my function:
Moralis.Cloud.afterSave("PlayersEntered", async (request) => {
const confirmed = request.object.get("confirmed")
if (confirmed) {
const CreatedWhoopys = Moralis.Object.extend("CreatedWhoopys")
const createdWhoopys = new CreatedWhoopys()
let query = new Moralis.Query("PlayersEntered")
const query1 = new Moralis.Query("CreatedWhoopys")
query1.equalTo("whoopyAddress", request.object.get("address")) //try using emitted address of whoopy instead of default table param
const item = await query1.first()
if(item) {
item.set("PlayersEntered", request.object.get("currentPlayersNumber"))
await item.save()
logger.info("Saved!")
} else {
logger.info("Not Found")
}
} else {
console.log("Error processing tx")
}
}
)
The function works correctly, and the item gets set correctly as well, however this only works one every two-three times the event is fired. Other times the value stays the same and doesnât update, even though the log says saved.
I am currently testing on Hardhat. Is this an issue with hardhat/moralis or is there something wrong with the logic?
Thanks!