This is surprising to me. The readme contains an example to query using key path, so I thought it should work.
I noticed one difference between my code and the example code. In the example code, the model is probably defined using Value.Required (because it's doing .select(\.age) without $). On the other hand, my code uses the @Field property wrapper.
I looked into the implementation of From.select(). It seems to support ValueContainer, but not FieldContainer. I guess this is the reason -- is this intentional?
Originally created by @pinkplus on GitHub (Jan 31, 2023).
Let's say we have the following model, with fields defined using the `@Field` property wrapper:
```swift
class Person: CoreStoreObject {
@Field.Stored("name")
var name: String = ""
@Field.Stored("age")
var age: Int = 0
}
```
The following query using key path will fail to compile:
```swift
let ages = try dataStack.queryAttributes(
From<Person>()
.select(\.$age)
)
```
This is surprising to me. The readme contains an example to query using key path, so I thought it should work.
I noticed one difference between my code and the example code. In the example code, the model is probably defined using `Value.Required` (because it's doing `.select(\.age)` without `$`). On the other hand, my code uses the `@Field` property wrapper.
I looked into the implementation of `From.select()`. It seems to support `ValueContainer`, but not `FieldContainer`. I guess this is the reason -- is this intentional?
Admittedly, queryAttributes() currently only supporting NSDictionary as the type parameter is a bit clunky.
@JohnEstropia commented on GitHub (Feb 1, 2023):
@pinkplus The [demo app](https://github.com/JohnEstropia/CoreStore/blob/1ed819b38d61a04845ad5512a0c09636dad4d7ff/Demo/Sources/Demos/Modern/TimeZonesDemo/Modern.TimeZonesDemo.MainView.swift#L105) shows the syntax you need:
```
let ages: [[String: Any] = try dataStack.queryAttributes(
From<Person>()
.select(NSDictionary.self, .attribute(\.$age))
)
```
Admittedly, `queryAttributes()` currently only supporting `NSDictionary` as the type parameter is a bit clunky.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @pinkplus on GitHub (Jan 31, 2023).
Let's say we have the following model, with fields defined using the
@Fieldproperty wrapper:The following query using key path will fail to compile:
This is surprising to me. The readme contains an example to query using key path, so I thought it should work.
I noticed one difference between my code and the example code. In the example code, the model is probably defined using
Value.Required(because it's doing.select(\.age)without$). On the other hand, my code uses the@Fieldproperty wrapper.I looked into the implementation of
From.select(). It seems to supportValueContainer, but notFieldContainer. I guess this is the reason -- is this intentional?@JohnEstropia commented on GitHub (Feb 1, 2023):
@pinkplus The demo app shows the syntax you need:
Admittedly,
queryAttributes()currently only supportingNSDictionaryas the type parameter is a bit clunky.@pinkplus commented on GitHub (Feb 4, 2023):
Hmm... Thanks.