Table Modify Assignment

Post your solutions here to the Table Modify Assignment.

ACTION helloworld::modify(uint64_t identifier, name new_owner, std::string new_name, uint64_t new_age){
  auto dog = _dogs.get(identifier, "Doggo not found");
  require_auth(dog.owner_name);
  auto dog_iterator = _dogs.find(identifier);
  _dogs.modify(dog_iterator, dog.owner_name,
  [&](auto& modify_dog){
    modify_dog.owner_name = new_owner;
    modify_dog.dog_name = new_name;
    modify_dog.age = new_age;
  });
}

I"ve left out the definition of the table but it seems to work without it, probably because I"ve added a declaration after defining the table type:

 typedef multi_index <name("dogs"), dog> dog_table;
  dog_table _dogs;
1 Like

ACTION edit(name dog_owner, int dog_id, int new_age, std::string new_name){
dog_index dogs(get_self(),get_self().value);
auto dog=dogs.find(dog_id);
require_auth(dog_owner);
dogs.modify(dog, dog_owner,[&](auto& selected) {
selected.dog_age=new_age;
selected.dog_name=new_name;
});
}

1 Like
ACTION mopdify(int id, string dog_name) {
      dog_index dogs(get_self(), get_self().value);

      auto dog = dogs.get(id, "Dog not find");
      require_auth(dog.owner);

      auto iterator = dogs.find(id);
      dogs.modify(iterator, dog.owner, [&](auto& dog){
        dog.dog_name = dog_name;
      }); 
}
1 Like

ACTION modify(int dog_id, std::string dog_name, int dog_age){
dog_index dogs(get_self(), get_self().value);
//require auth so only owner can erase its dogs.
auto dog = dogs.get(dog_id,“Unable to fetch dog. Or no dog”);
require_auth(dog.owner);
//end auth
auto iterator = dogs.find(dog_id);
dogs.modify(iterator, dog.owner, [&](auto& dog){
dog.dog_name = dog_name;
dog.dog_age = dog_age;
});
}

working by ID, cant modify ID nor owner, only name and age.

1 Like