Replies: 1 comment 1 reply
-
|
Hi @ddunlea, I didn't have time to look deeply into your code, but I can see that there is an easier way to achieve what you want. You can use So when I refactor your @Selection @CasePathable
public enum FirstOrSecond: Equatable, Sendable {
case first(First)
case second(Second)
public static func all() -> some Statement<FirstOrSecond> {
First.select {
FirstOrSecond.Selection.first($0)
}
.union(
Second.select {
FirstOrSecond.Selection.second($0)
}
)
}
}…then the following test passes: #expect(
firstOrSecond == [
.second(Second(id: 1, name: "second", count: 2)),
.first(First(id: 1, name: "first", description: "description")),
]
) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to select 2 unrelated types via a union such that the resultant type is essentially a not-particularly-type-safe OR of the 2
I define 2 types:
and then I define a selection which is an OR of them:
I have a test that inserts one of each type, and then tries to select both:
At first, I thought that the multiple
AS "name"selections were a factor so I renamed the fields tofirstnameandsecondnamerespectively. This didn't help, but I did then realise that there are multipleAS "id"parts so I changed the types to have fields namedid1andid2. At this point, the test did pass, but I don't think that's a practical fix as it breaks the code idiom. For exampleFirst.Draftexpects the id field to be namedidSample code to reproduce the problem can be found here on the union-demo branch of my sandbox repo
Beta Was this translation helpful? Give feedback.
All reactions