Skip to content

[orm] hydrate fetched objects that are known in pool/identifymap #636

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

Open
marcj opened this issue Mar 11, 2025 · 0 comments
Open

[orm] hydrate fetched objects that are known in pool/identifymap #636

marcj opened this issue Mar 11, 2025 · 0 comments

Comments

@marcj
Copy link
Member

marcj commented Mar 11, 2025

async multipleJoins(databaseFactory: DatabaseFactory) {
bookstore:multipleJoins:


        {
            const review = await database.query(Review)
                .innerJoinWith('book')
                .innerJoinWith('user')
                .findOne();
            console.log('review', review);
            console.log('review.user', review.user);
            expect(review.user.id).toBe(user.id);
            expect(review.book.id).toBe(book.id);
            // author became hydrated since we loaded the full user object also
            expect(review.book.author.name).toBe('Peter');
            expect(review.user.name).toBe('Peter');
            expect(review.book.title).toBe('Great');
            expect(review.status).toBe(ReviewStatus.hidden);
        }

since review.user === review.book.user and user is joined (fully loaded) it's necessary that both objects are the same. currently review.book.author is a unhydrated reference. the reference should hydrate as soon as the full user is found. we have the reference in formatter pool.

Also as soon as identity map is enabled for this query the formatter breaks. concretely: review.user becomes a reference and is never hydrated because it was first found in review.book.author as reference and stays a reference. we need to check first for pool then identitymap (identitymap alone is not hydrated when new information is available)

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

No branches or pull requests

1 participant