Remove data
Authorize Action
Provide authorization, os only the user himself can delete his composition isntance from contracts database
Authorize Action
[[inery::action]] void database::del( name owner ) {
// Require Owners Authentification
require_auth(owner);
}
Find The Owner You Want To Delete
Use the multi-index find( )
method to locate the owner object you want to delete. The targeted owner is searched based on its account name.
Find Iterator
[[inery::action]] void database::del( name owner ) {
require_auth(owner);
// check if the owner already exists
auto itr = container.find(owner.value);
}
Remove The Owner If Found
Check to see if the owner exists and use erase( )
method to delete the row from composition. Otherwise print an informational message and return.
container.erase( itr );
This command eraseowner
instance fromcontainer
composition.
Full Remove Action
[[inery::action]] void database::del( name owner ) {
require_auth(owner);
auto itr = container.find(owner.value);
check(itr != container.end(), "Owner does not exist in composition, nothing to delete")
container.erase( itr );
}
Delete Action Advisory
It is mandatory to delete your composition instances if you are overriding the contract structure. Failing to delete old instances can result in dangling data, which may lead to security vulnerabilities or unexpected behavior in your contract.