Skip to content

Children not populated when retrieving parent #46

Description

@Pikachews

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?

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions