Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deconstruct structs with arrays? #24

Closed
roland-KA opened this issue Nov 3, 2023 · 2 comments
Closed

How to deconstruct structs with arrays? #24

roland-KA opened this issue Nov 3, 2023 · 2 comments

Comments

@roland-KA
Copy link

I've tried Strapping.jl on the following example:

struct Person
    id::Int64
    firstname::String
    lastname::String
end

struct Club
    id::Int64
    name::String
    members::Array{Person}
end

StructTypes.StructType(::Type{Person}) = StructTypes.Struct()
StructTypes.idproperty(::Type{Person}) = :id
StructTypes.StructType(::Type{Club}) = StructTypes.Struct()
StructTypes.idproperty(::Type{Club}) = :id

p1 = Person(1, "John", "Smith")
p2 = Person(2, "Mary", "Miller")
c1 = Club(1, "chess club", [p1, p2])

club_table = Strapping.deconstruct(c1)

Applying deconstruct on c1 I expected to get all information within this struct in a tabular form. But somehow deconstruct cannot cope with the array within this struct. I'm getting the following results:

julia> fc = first(club_table)
Strapping.DeconstructedRow{Club}: (id = 1, name = "chess club", members_id = 1, members_firstname = "John", members_lastname = "Smith")

Only the first member of the club (John Smith) es retrieved. How can I get all the data within c1 in a tabular form in order to store it in a relational database?

@qwjyh
Copy link

qwjyh commented Sep 19, 2024

Actually, the other member is stored in the second row.

julia> using DataFrames

julia> club_table |> DataFrame
2×5 DataFrame
 Row │ id     name        members_id  members_firstname  members_lastname
     │ Int64  String      Int64       String             String
─────┼────────────────────────────────────────────────────────────────────
   11  chess club           1  John               Smith
   21  chess club           2  Mary               Miller

@roland-KA
Copy link
Author

Oh, of course 🤦‍♂️. Thanks! Sometimes I don't see the obvious 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants