question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deep relation when querying

See original GitHub issue

Issue type:

[x] question [ ] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [x] mysql / mariadb [ ] oracle [ ] postgres [ ] sqlite [ ] sqljs [ ] react-native

TypeORM version:

[x] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

It is possible to pass a deep relation when querying? For example, I have a User, a User can have many cars and a Car has one Make. When I query the User I want to get his cars and each Car’s Make. I don’t want to use Eager or Lazy loading. I’m thinking something like:

$users = User.find({relations : ['cars.make']})

If no, are there any plans for implementing it in the near future? As an example, I saw this behavior in the PHP Laravel Framework

Thank you!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

12reactions
IonelLupucommented, May 11, 2018

I was referring to the fact that I have to explicitly write every relation like so:

$users = User.find({relations : ['cars','cars.make']})

But it would be nice to write it only once like so:

$users = User.find({relations : ['cars.make']})

It’s kinda redundant to write car twice. If I want to remove the cars relation I have to remove any other relation linked with the car too.

For example, this is my current code:

User.find({relations: ['client', 'client.cars', 'client.cars.version', 'client.cars.version.model', 'client.cars.version.model.make']});

A better version could be like so:

User.find({relations: ['client.cars.version.model.make']});
1reaction
pleerockcommented, May 11, 2018

yes its supported as documentation says, did you try it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Query by deep properties on relations - Stack Overflow
You should think of relations as SQL joins, it is quite simple with TypeOrm to define them on entities as you build query...
Read more >
Laravel Eloquent: Deeper Relationships with One Query
If you work with a project that has multiple levels of hasMany relationships, you can use hasManyThrough instead, or one of a few...
Read more >
Where clause in deep nested relation - Laracasts
Where clause in deep nested relation. I have a query for retrieving the user's company yearly periods, documents, clients and presentations.
Read more >
Relation queries (Concepts) - Prisma
Prisma Client provides convenient queries for working with relations, such as a fluent API ... Relation queries include: ... Include deeply nested relations....
Read more >
Understanding Relationship Query Limitations | SOQL and ...
Understanding Relationship Query Limitations · Relationship queries are not the same as SQL joins. · No more than 55 child-to-parent relationships can be ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found