Skip to content

Collection columns / .from() reference field bug #610

Closed

Description

@fcannizzaro

There is a weird effect caused by the collection's reference name and its columns.

If the string used to reference the collection in the from is also a field of the collection's schema the query breaks.

type Schema = {
	email: string;
	createdAt: Date;
}

const emailCollection = createCollection<Schema>({ ... }); 

// This works fine
const result = useLiveQuery(q => 
	q
		.from({ t: emailCollection } )
		.orderBy(({ t }) => t.createdAt, "desc")
);

// This breaks
const result = useLiveQuery(q => 
	q
		.from({ email: emailCollection } )
		.orderBy(({ email }) => email.createdAt, "desc")
);

Right now I discovered that this breaks at least the sorting. In this case for "breaks" I mean that there is no sorting.

Activity

  1. moved this from In Progress to Todo in TanStack DB 1.0.0 releaseon Sep 30, 2025
  2. samwillis commented on Oct 3, 2025

    @samwillis
    Collaborator

    Thats for the report, this was due to some legacy code that was attempting to support using a select alias in a orderBy, but thats not the intended design and we don't support it at the type level. I've removed the code and fixed it in #637

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

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions