3

can i use the id of a struct in an other struct as return value for multi_index? like:

//@abi table test i64
struct st_test{
    uint64_t id;
    string name;
    uint64_t primary_key() const {return id;}
    /*
    ...
    */
    }

//@abi table main i64
struct st_main {
    uint64_t id;
    st_test other_struct;

    uint64_t primary_key() const {return id;}
    uint64_t by_other_struct() const{return other_struct.id;}
    /*
    ...
    */
    }

    /*
    ...
    */
  • So, why not just store the id of the another struct but store the whole struct? – Jimmy Guo Jul 22 '18 at 14:08
1

Yes this is possible, the devil is in the details though.

You have to make sure that you correctly serialize both structs, and that you set up the secondary index for the 2nd struct ID correctly in the multi_index table.

However, doing it this way will use up a lot of space in your table as you would have the full other_struct within your st_main struct. It might be better to have two separate tables, and have one table reference the ID in the other somehow. This obviously depends somewhat on your use case though.

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.