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

feat: Adding relations option to findTrees() #7974

Closed
TheProgrammer21 opened this issue Jul 29, 2021 · 4 comments · Fixed by #7981
Closed

feat: Adding relations option to findTrees() #7974

TheProgrammer21 opened this issue Jul 29, 2021 · 4 comments · Fixed by #7981

Comments

@TheProgrammer21
Copy link
Contributor

TheProgrammer21 commented Jul 29, 2021

Feature Description

Adding functionality to load relations in TreeRepositories.

The Problem

When loading a tree in TypeORM there is no possibility of loading relations of the tree entities.

The Solution

Adding a relations option to the findTrees() function like it already exists for find() or findOne() in non TreeRepositories.

Considered Alternatives

A workaround would be to manually write raw queries with JOINs and execute those.

Relevant Database Driver(s)

DB Type Relevant
aurora-data-api yes
aurora-data-api-pg yes
better-sqlite3 yes
cockroachdb yes
cordova yes
expo yes
mongodb yes
mysql yes
nativescript yes
oracle yes
postgres yes
react-native yes
sap yes
sqlite yes
sqlite-abstract yes
sqljs yes
sqlserver yes

Are you willing to resolve this issue by submitting a Pull Request?

  • ✅ Yes, I have the time, and I know how to start.
  • ✅ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
@TheProgrammer21
Copy link
Contributor Author

I have a problem with my unit tests: They always pass, even if they should not.

import "reflect-metadata";
import { expect } from "chai";
import { Connection } from "../../../src";
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils";
import { Category } from "./entity/Category";
import { Site } from "./entity/Site";

describe("github issues > #7974 Adding relations option to findTrees()", () => {

  let connections: Connection[];
  before(async () => connections = await createTestingConnections({
    entities: [__dirname + "/entity/*{.js,.ts}"],
    schemaCreate: true,
    dropSchema: true,
    enabledDrivers: ["mssql"]
  }));

  beforeEach(() => reloadTestingDatabases(connections));
  after(() => closeTestingConnections(connections));

  it("github issues > #7974 should return tree with sites relation", () => Promise.all(connections.map(async connection => {
    
    ...

    let x = await connection.getTreeRepository(Category).findTrees({ relations: ["sites"] });

    expect.fail("test to fail");

  })));

});

This is the output on the console:


> mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test "--grep=github issues > #7974"



  github issues > #7974 Adding relations option to findTrees()
    √ github issues > #7974 should return tree with sites relation


  1 passing (66ms)

I also don't see any console.log() outputs.

Does anyone have an idea? I did stick to the recommended testing template: https://github.com/TheProgrammer21/typeorm/blob/master/DEVELOPER.md#running-tests-locally

@TheProgrammer21
Copy link
Contributor Author

I was able to aggregate the problem: The connections array is empty. Im now debugging..

@imnotjames
Copy link
Contributor

You need to set up an ormconfig for it. See the example used by circleci

@TheProgrammer21
Copy link
Contributor Author

TheProgrammer21 commented Jul 29, 2021

You need to set up an ormconfig for it. See the example used by circleci

Ah I see.. I didn't run all DBMS but they were not skipped in the ormconfig. Probably something that could be mentioned in the development guide.

Thanks for the help!

pleerock pushed a commit that referenced this issue Aug 4, 2021
* feat: add relation option to tree queries

Add possibility to load relations of tree entities

Closes: #7974 #4564

* style: remove unused declaration

remove unused declaration to satisfy linting.

* Update tree-entities.md

docs: rename variable for copy paste

* Update FindOptionsUtils.ts

style: remove prettified code

* style: remove prettified code

* style: remove prettified code

* test: enable test for all drivers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants