Here's a suggestion:
Change the last line to
mapping(byte32 => Track) public trackStructsd;
This will be less confusing overall when you add the indices you need to enumerate things two more ways.
Before we complicate the contract, consider if this is really needed or just the first idea: https://blog.b9lab.com/the-joy-of-minimalism-in-smart-contract-design-2303010c8b09
You can have indices. For example, to enumerate the ids in the mapping:
bytes32[] public trackIdList; // .push(key) as you insert records
You can have a list of rc
and a list of sn
.
bytes32[] public rc;
bytes32[] public sn;
You can have a lists of the Tracks pointed to by each rc
and sn
.
mapping(bytes32 => bytes32[]) public rcTrackList; // .push as you go
mapping(bytes32 => bytes32[]) public snTrackList; // .push as you go
That will handle address an append-only case where you don't need to update the rc
or sn
in a track, ever. Matters get more complicated in the common case that you need to do just that. That is, in effect, deleting a row from a list. You will find there is still no efficient way to approach that. It's doable.
A full pattern to add/modify/delete and enforce referential integrity in a one-to-many relationship: https://medium.com/@robhitchens/enforcing-referential-integrity-in-ethereum-smart-contracts-a9ab1427ff42
Hope it helps.