@@ -37,9 +37,11 @@ public struct Query<T: PersistentModel> {
3737
3838 /// A range representing the number of results to skip before returning matches and maximum number of results to fetch. When `nil`, the query will return all matching results.
3939 public var range : Range < Int > ?
40-
40+
41+ /// Key paths representing related models to fetch as part of this query.
4142 public var relationshipKeyPaths : [ PartialKeyPath < T > ] = [ ]
42-
43+
44+ /// The subset of attributes to fetch for this entity
4345 public var propertiesToFetch : [ PartialKeyPath < T > ] = [ ]
4446
4547 /// SwiftData compatible sort descriptors generated from the query's sort configuration.
@@ -298,36 +300,41 @@ public extension Query {
298300}
299301
300302public extension Query {
301- /// Returns a new query that prefetches the specified relationship when executing the fetch.
303+ /// Returns a new query that prefetches the specified relationships when executing the fetch.
302304 ///
303305 /// Prefetching relationships can improve performance by reducing the number of database
304- /// trips needed when accessing related objects. Multiple relationships can be prefetched
305- /// by chaining multiple calls to this method.
306- ///
307- /// - Parameter keyPath: Key path to the relationship property to prefetch
308- /// - Returns: A new query with the additional relationship marked for prefetching
309- ///
310- /// ## Example
311- /// ```swift
312- /// // Prefetch single relationship
313- /// let ordersWithCustomers = Order
314- /// .include(#Predicate { $0.status == .active })
315- /// .prefetchRelationship(\.customer)
306+ /// trips needed when accessing related objects.
316307 ///
317- /// // Prefetch multiple relationships
318- /// let ordersWithDetails = Order
319- /// .prefetchRelationship(\.customer)
320- /// .prefetchRelationship(\.items)
321- /// ```
322- func prefetchRelationship( _ keyPath: PartialKeyPath < T > ) -> Self {
308+ /// - Parameter keyPaths: Array of key paths to the relationships to prefetch
309+ /// - Returns: A new query with the additional relationships marked for prefetching
310+ func prefetchRelationships( _ keyPaths: [ PartialKeyPath < T > ] ) -> Self {
323311 Query (
324312 predicate: predicate,
325313 sortBy: sortBy,
326314 range: range,
327- prefetchRelationships: relationshipKeyPaths + [ keyPath ] ,
315+ prefetchRelationships: relationshipKeyPaths + keyPaths ,
328316 propertiesToFetch: propertiesToFetch
329317 )
330318 }
319+
320+ /// Returns a new query that prefetches the specified relationships when executing the fetch.
321+ ///
322+ /// Prefetching relationships can improve performance by reducing the number of database
323+ /// trips needed when accessing related objects.
324+ ///
325+ /// - Parameter keyPaths: Key paths to the relationships to prefetch
326+ /// - Returns: A new query with the additional relationships marked for prefetching
327+ ///
328+ /// ## Example
329+ /// ```swift
330+ /// // Prefetch multiple relationships
331+ /// let ordersWithDetails = Order
332+ /// .include(#Predicate { $0.status == .active })
333+ /// .prefetchRelationships(\.customer, \.items)
334+ /// ```
335+ func prefetchRelationships( _ keyPaths: PartialKeyPath < T > ... ) -> Self {
336+ prefetchRelationships ( keyPaths)
337+ }
331338
332339 /// Returns a new query that fetches only the specified key paths when executing the fetch.
333340 ///
0 commit comments