Typeorm: Load data from junction table

Created on 27 Jul 2017  路  3Comments  路  Source: typeorm/typeorm

Do we have any way other than using raw sql query to load data from a junction table? What I want to do is simply check for the existence of the specifiedid.

My use-case: it's a junction table for likes and I want to check if an user has liked an article. So the query I want to use

SELECT * FROM "article_likes_user" WHERE "articleId" = :articleId AND "userId" = :userId
accepting PRs query builder new feature

Most helpful comment

There is no at the moment. But I plan to implement such functions in the RelationQueryBuilder in the future. Something like this:

const isUserLiked = await connection.createQueryBuilder(Article)
     .relation("likedUsers")
     .has(user)
     .execute();

You can implement it on your own if you want

All 3 comments

There is no at the moment. But I plan to implement such functions in the RelationQueryBuilder in the future. Something like this:

const isUserLiked = await connection.createQueryBuilder(Article)
     .relation("likedUsers")
     .has(user)
     .execute();

You can implement it on your own if you want

Relational query builder functionality is implemented in latest version, you can find docs on site.

Sorry, is this feature still working in? I can't find the method .has in RelationQueryBuilder.ts

There is no at the moment. But I plan to implement such functions in the RelationQueryBuilder in the future. Something like this:

const isUserLiked = await connection.createQueryBuilder(Article)
     .relation("likedUsers")
     .has(user)
     .execute();

You can implement it on your own if you want

Was this page helpful?
0 / 5 - 0 ratings