Skip to content
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

Children not populated when retrieving parent #46

Open
Pikachews opened this issue Feb 11, 2024 · 0 comments
Open

Children not populated when retrieving parent #46

Pikachews opened this issue Feb 11, 2024 · 0 comments

Comments

@Pikachews
Copy link

Not sure if this is supposed to be a capability of this library or not, but when I add the following unit test to this library to test whether it works:

      describe('parent has children', async () => {
        it('Can find parent with children', async () => {
          const repository = AbstractPolymorphicRepository.createRepository(
            connection,
            AdvertRepository,
          );
          const userRepository = connection.getRepository(UserEntity);

          const user = await userRepository.save(new UserEntity());

          await repository.save([
            repository.create({
              owner: user,
            }),
            repository.create({
              owner: user,
            }),
          ]);

          const result = await userRepository.find();
          result.forEach((res) => {
            expect(res).toBeInstanceOf(UserEntity);
            expect(res.adverts).toBeInstanceOf(Array);
            expect(res.adverts.length).toBe(2);
          });
        });
      });

users returned from userRepository.find() always have res.adverts === undefined. I would've expected this field to be populated when retrieving from the repository.
I also added eager: true to the adverts field of UserEntity but that didn't make any difference.

Am I doing something wrong?

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