Skip to content

findOne returning Collection in subquery #1451

Description

@boyswan
  • I've validated the bug against the latest version of DB packages

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

In the following example:

const { data: users } = useLiveQuery(q =>
  q.from({ u: userCollection })
    .select(({ u }) => ({
      user: u,
      team: q
        .from({ t: teamCollection })
        .where(({ t }) => eq(t.id, u.team_id))
        .findOne()
    })))

Expected behavior

The following team is type Collection. I would it expect it to be Team | undefined.

const team = users[0].team  // type Collection

Ideally this would behave similar to toArray and return a materialized object.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions