Defining methods on Updates<MySelection> #274
|
Hey @stephencelis, we made some fixes for From that change:
Originally posted by @stephencelis in #233 The issue is that I've defined methods on selection types in the same way that you'd do so for table types, via @Selection struct NestedFields {
var honestCount: Int = 0
var optionalCount: Int?
}
extension Updates<NestedFields> {
mutating func modify(count: Int) {
self.honestCount = count
self.optionalCount = Optional(count)
}
}
@Test func mutateSelectionFields() {
assertInlineSnapshot(
of: Root.update {
$0.fields.modify(count: 4)
},
as: .sql
)
}Now it looks like I'd have to define it like this: extension Updates<TableAlias<NestedFields, _TableAliasName<Root>>> {
mutating func modify(count: Int) {
self.honestCount = count
self.optionalCount = Optional(count)
}
}Which is unfortunate since now public typealias UpdatesOf<S, B> = Updates<TableAlias<S, _TableAliasName<B>>> where S: Table & QueryExpression, B: TableSo I guess the question is: it possible to define selection updates on a type with one generic? |
Replies: 1 comment 1 reply
|
Can you constrain the helper itself with generics? extension Updates {
mutating func modify<S, B>(count: Int) where /* constraints */ {
…
}
}Since this doesn't appear to be a bug I'm going to convert to a discussion. |
Can you constrain the helper itself with generics?
Since this doesn't appear to be a bug I'm going to convert to a discussion.