Skip to content
Discussion options

You must be logged in to vote

Hi @importRyan, your tables are not modeled the correct way for SQL. A parent table does not hold onto all of its child values. Instead, the child table has a foreign key pointing to its parent:

@Table
struct Exercise: Identifiable {
  let id: String
}

@Table
struct BodyRegion: Codable {
  let id: String
  var name: String
  let exerciseID: Exercise.ID
}

Then you can define a @Selection that selects all exercises along with their trained body regions like so:

@Selection
struct DetailScreenSelection {
  let exercise: Exercise
  @Column(as: [BodyRegion].JSONRepresentation.self)
  let trained: [BodyRegion]
}

And then the query to select into this data type can be done simply as:

func query() {

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by importRyan
Comment options

You must be logged in to vote
1 reply
@mbrandonw
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants