Skip to content
Discussion options

You must be logged in to vote

Hi @rcasula, this is quite a complex query to be performing and so it takes some work to get things in the right shape. The trick is to use a common table expression to first select all the data for the ExpenseModel, and then you aggregate that selection into a GroupedExpenses using jsonGroupArray.

First some fixes to your data types to be identifiable and codable:

@Table
struct Currency: Codable, Identifiable {
  let code: String
  let name: String
  let symbol: String
  var id: String { code }
}

@Table
struct Expense: Codable, Identifiable {
  let id: UUID
  let name: String
  let amount: Int
  let currencyCode: Currency.ID
  let date: Date
}


// I want to achieve this end result:

@S…

Replies: 2 comments 13 replies

Comment options

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

You must be logged in to vote
13 replies
@mbrandonw
Comment options

@andrefmsilva
Comment options

@rcasula
Comment options

@mbrandonw
Comment options

@rcasula
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
3 participants