Hi there, Sorry for my lack of knowledge
At this time I sync my contract events each time a product is put on sales on my ProductOnSales table, but I only get 3 values i configure in my smart contract, I want to inject a new column which contain the productURI, which I store it in table Product, Is there any solution which every I emit the event it will automatically inject a ProductURI column in ProductOnSales for me which I stored in Product table.
Thank you .
You can use a hook like beforeSave or afterSave for this
I already using BeforeSave for this situation, but i dont know how to inject a column at this table with the value already have from another table. Thank for your help.
Like in User table I can use request.user.attributes.accounts, so I can get the _User table value and set it to my new Table ?
You can do a query in another table. I don’t understand what doesn’t work.
You don’t have access to the user object if it is an event sync.
like in this case, which token represent for Token table, i want to get that attributes value
Is there any solution I can define that Token object ?
Thank you
I still don’t understand the question. You already have that data in a table? And you only need to make a query or you don’t know how to add a column to an existing table or something else?
I mean for example i have table A, and I want whenever a event in table A is emit, it will inject a new column with a data which have existed in table B, like in ProductOnSales tables I just have productAddress, productId and price, when productURI is stay in Product table, i want bring the productURI from Product table to ProductOnSales table
Moralis.Cloud.beforeSave('ItemForSales', async(request) =>{
const confirmed = request.object.get('confirmed');
const logger = Moralis.Cloud.getLogger();
logger.info('Ready for putting Item on Sale');
if(confirmed){
const item = Moralis.Object.extend('ItemForSales');
const NFT = Moralis.Object.extend("NFT")
const itemQuery = new Moralis.Query(item);
const query = new Moralis.Query(NFT);
query.equalTo('nftAddress', request.object.get('nftAddress'));
query.equalTo('tokenId', request.object.get('tokenId'));
// inject new column
}})
In this case I have 2 table and I want whenever i trigger Putting an Item on sales, table ItemForSales can inject a new column which is tokenURI, which already stored in NFT table.
You use a simple object.set
You also have to add that column in the dashboard interface so that you can see it in the dashboard
Yes I know, but I’m stuck in how to get the NFT table data ( in this case is tokenURI column in NFT table)
can I do something like
item.set('tokenURI', request.NFT.attributes.tokenURI);
You have to make a query first to get that data that you want to set. The you can use logger.info(JSON.stringify(variabile_name)) to SEE if it haÈ™ the expected value and after that you could set it.
Thank you, I will trying some ways