Skip to content

@FetchOne: Automatically observe primary-keyed records - #519

Merged
stephencelis merged 1 commit into
mainfrom
fetch-one-autosubscribe
Aug 11, 2026
Merged

@FetchOne: Automatically observe primary-keyed records#519
stephencelis merged 1 commit into
mainfrom
fetch-one-autosubscribe

Conversation

@stephencelis

Copy link
Copy Markdown
Member

Right now a @FetchOne merely fetches the first row of a table, meaning if you forget to initialize it with a query, it could reload with the wrong data (simply the first row of the table):

struct ProfileView: View {
  @FetchOne var profile: Profile

  init(profile: Profile) {
    _profile = FetchOne(wrappedValue: profile, Profile.find(profile.id))
  }

  var body: some View { /* ... */ }
}

To avoid this bug, let's bake this behavior into @FetchOne.

Right now a `@FetchOne` merely fetches the first row of a table, meaning
if you forget to initialize it with a query, it could reload with the
wrong data (simply the first row of the table):

```swift
struct ProfileView: View {
  @FetchOne var profile: Profile

  init(profile: Profile) {
    _profile = FetchOne(wrappedValue: profile, Profile.find(profile.id))
  }

  var body: some View { /* ... */ }
}
```

To avoid this bug, let's bake this behavior into `@FetchOne`.
@stephencelis
stephencelis requested a review from mbrandonw August 10, 2026 22:24
@stephencelis
stephencelis merged commit 8c6d7d0 into main Aug 11, 2026
5 checks passed
@stephencelis
stephencelis deleted the fetch-one-autosubscribe branch August 11, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants