0

I have a contract that registers user's attended universities. The data structure is the following:

struct University {
    string name; // name of the university
    address addr; // address of the poster
}

Uni[] private unis;

Then, I have the following mapping:

mapping (uint256 => address) idToPoster;

The contract functionality works when I want to query the struct data according to the Id of the post, but since every address can create several records, what would be the best way to get all the posts by a certain address querying by that address?

1

The simplest solution would be to have another mapping, something like

mapping(address => uint[]) posterToIds;

And add the post id to that array of uints every time someone creates a post.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.