Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot fetch fields of @Group submodel. #618

Open
Jean-Daniel opened this issue Oct 6, 2024 · 1 comment
Open

Cannot fetch fields of @Group submodel. #618

Jean-Daniel opened this issue Oct 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Jean-Daniel
Copy link

Jean-Daniel commented Oct 6, 2024

Describe the issue

Trying to use a field from a @Group struct in methods like .field(), .all(), etc fails with an error like Instance method 'all' requires the types 'User' and 'GroupPropertyPath<User, FieldProperty<Pet, String>>.Model' (aka 'Pet') be equivalent.

FluentKit version

1.49.0

Operating system and version

macOS 14.7

Swift version

Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)

Steps to reproduce

Create a Vapor project.

Define the following model:

final class Pet: Fields {
    // The pet's name.
    @Field(key: "name")
    var name: String

    // The type of pet.
    @Field(key: "type")
    var type: String

    // Creates a new, empty Pet.
    init() { }
}
final class User: Model {

  static var schema: String = "users"

  @ID(key: .id)
  var id: UUID?

  // The user's nested pet.
  @Group(key: "pet")
  var pet: Pet
}

Try to build a query using that model

func query(req: Request) {
  User.query(on: req.db).filter(\.$pet.$name == "Zizek").all(\.$pet.$name)
}

Build the project.

Outcome

The build fails with the error:

Instance method 'all' requires the types 'User' and 'GroupPropertyPath<User, FieldProperty<Pet, String>>.Model' (aka 'Pet') be equivalent.

Additional notes

No response

@Jean-Daniel Jean-Daniel added the bug Something isn't working label Oct 6, 2024
@Jean-Daniel Jean-Daniel changed the title Cannot fetch fields of @Group submodes. Cannot fetch fields of @Group submodel. Oct 6, 2024
@0xTim
Copy link
Member

0xTim commented Oct 9, 2024

I don't think this is supported behaviour. The @Group is supposed to be all fetched so that we can populate it correctly. I'd say if you need to retrieve specific fields you should look at flattening the model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants