Hello!
Iām having a bit of trouble using the Moralis Database Object ā.extend()ā method.
I have a React component called āRegisterā that registers new users. Inside this component I want to save two different kinds of database objects, a āVendorā record and a āOwnerā record.
I know that you have to include the useNewMoralisObject() hook, but am having trouble getting it to work properly.
First, I load the hooks from the library:
import {
useMoralis,
useWeb3ExecuteFunction,
useNewMoralisObject
} from "react-moralis";
Then inside the component, I load the āsaveā function from the hook:
const {save} = useNewMoralisObject("Vendor");
Then I declare a function that will gather input and handle the submission:
const createVendor = () => {
const Vendor = Moralis.Object.extend("Vendor");
Moralis.Object.registerSubclass("Vendor", Vendor);
let newVendor = {
/*... vendor meta data ... */
}
save(newVendor, {
onSuccess: (savedVendor) => { /* success actions here */},
onError: (err) => {/* error handling here */ }
});
}
It worked one time and I can see that entry in the database, but now subsequent calls to make a new entry in the Moralis Database fail, and Iām not sure why, or even if Iām doing this right? I also want the ability to save another related record under a different āclass nameā (Owner), but Iām not sure how to do that?
Can someone give me a bump in the right direction? I would appreciate any guidance.
Thanks in advance!