Swift-Kuery-ORM icon indicating copy to clipboard operation
Swift-Kuery-ORM copied to clipboard

How do I build a custom query if all I have is a Table?

Open Morpheu5 opened this issue 6 years ago • 2 comments

With reference to #35, I am trying to build a series of queries to do my own validation before saving/updating my models. The docs suggest to retrieve the table like this

do {
  let table = Grade.getTable()
} catch {
  // Error
}

and then use it to build a plain old Query using Swift-Kuery. However, getTable() returns a Table, which obviously has none of the keys of Grade, because it is not a Table).

Any pointers? :)

Morpheu5 avatar May 05 '18 15:05 Morpheu5

Hey @Morpheu5 , an idea would be to extend your Grade Model - like this:

extension Grade {
   func save(....) {
     // Validation
     // Create Query with Table 
     // Execute Query
   }
}

The extension in Grade will overwrite the extension of Model Have a look at the Model.swift code for reference. Let me know if that solves the problem

EnriqueL8 avatar May 09 '18 21:05 EnriqueL8

@Morpheu5, Do you need any further assistance with this issue?

kilnerm avatar Nov 19 '18 10:11 kilnerm