HaxeFoundation / record-macros

Macro-based ORM (object-relational mapping)
MIT License
49 stars 24 forks source link

Arbitrary Serialized Data #17

Closed piboistudios closed 6 years ago

piboistudios commented 6 years ago

I was reading the readme and taking notes on the library. Everything seems rather straightforward, and the examples are concise except for in the case of Arbitrary Serialized Data section.

For example, using this snippet:

import sys.db.Types
enum PhoneKind {
    AtHome;
    AtWork;
    Mobile;
}
class User extends sys.db.Object {
    public var id : SId;
    ...
    public var phones : SData<Array<{ kind : PhoneKind, number : String }>>;
}

I understand that the phones member would have to be reflected into a Bytes array, how would I then convert this into an Array of typedef pairs of PhoneKinds and Strings ?

Sorry if this is a novice question, and not really an issue, wasn't really sure where else to inquire about this.

piboistudios commented 6 years ago

Short answer:

You don't have to do anything lol. It's already a Dynamic guys. Just treat it like whatever you thought it was or cast() it to that type

My own past horrible experiences with loose casting steered me away from this very simple answer.