Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 如何限制类型联接查询?_Postgresql_Nestjs_Typeorm - Fatal编程技术网

Postgresql 如何限制类型联接查询?

Postgresql 如何限制类型联接查询?,postgresql,nestjs,typeorm,Postgresql,Nestjs,Typeorm,我是打字新手,也许有人能解决我的问题。 我使用的是NestJS和TypeORM,有两个表(类别和天赋)。我希望找到一个解决方案来限制TypeForm联接查询 每个类别在人才工作中可以有许多人才,每个人才在人才工作中可以有许多类别。 我喜欢找到所有类别和受尊敬的人才,但我希望(限制)只有五个人才 人才: @实体(“人才”) @唯一(['mobile'])) 导出类TalentsEntity扩展BaseEntity{ @PrimaryGeneratedColumn('uuid') id:字符串; @

我是打字新手,也许有人能解决我的问题。 我使用的是NestJS和TypeORM,有两个表(类别和天赋)。我希望找到一个解决方案来限制TypeForm联接查询

每个类别在
人才工作
中可以有许多人才,每个人才在
人才工作
中可以有许多类别。 我喜欢找到所有类别和受尊敬的人才,但我希望(限制)只有五个人才

人才

@实体(“人才”)
@唯一(['mobile']))
导出类TalentsEntity扩展BaseEntity{
@PrimaryGeneratedColumn('uuid')
id:字符串;
@列({nullable:true})
名称:字符串;
@列({unique:true})
移动:字符串;
@列({nullable:true})
电子邮件:字符串;
@列({select:false})
密码:字符串;
@列({select:false})
盐:细绳;
@列({default:false})
isBlocked:布尔;
@列({default:true})
isActive:布尔型;
//与类别模型的关系
@许多(
类型=>类别实体,
categoriesEntity=>categoriesEntity.talent\u工作,
{渴望:真的},
)
@JoinTable({name:'人才\工作\类别'})
工作类别:类别实体[];
}
类别

@实体(“类别”)
@唯一(['title']))
导出类CategoriesEntity扩展BaseEntity{
@PrimaryGeneratedColumn('uuid')
id:字符串;
@列({nullable:true})
标题:字符串;
//与人才的关系
@许多(
类型=>才智,
talentsEntity=>talentsEntity.working_类别,
{eager:false},
)
才干:才干[];
}
这是我到目前为止的打字查询

const query=wait this.createQueryBuilder('category');
query.leftJoinAndSelect('category.talent_worked','talent');
query.leftjoin和select('talent.working_categories'、'talentCategories');
其中('talent.isActive=:isActive和talent.isBlocked=:isBlocked',{isActive:true,isBlocked:false});
if(categoryId)query.andWhere('category.id=:categoryId',{categoryId});
query.select([
“category.id”,
“类别.标题”,
'天赋.id',
“人才.姓名”,
“talentCategories.id”,
“人才类别.标题”,
]);
query.orderBy('category.created_at','ASC');
query.addOrderBy('talent.created_at','ASC');
return wait query.getMany();
您可以向查询中添加.limit(count)。 您的打字代码将是

  const query = await this.createQueryBuilder('category');
    query.leftJoinAndSelect('category.talent_worked', 'talent');
    query.leftJoinAndSelect('talent.working_categories', 'talentCategories');
    query.where('talent.isActive = :isActive AND talent.isBlocked = :isBlocked', { isActive: true, isBlocked: false});
    if (categoryId) query.andWhere('category.id = :categoryId', { categoryId });
    query.select([
        'category.id',
        'category.title',
        'talent.id',
        'talent.name',
        'talentCategories.id',
        'talentCategories.title',
    ]);
    query.orderBy('category.created_at', 'ASC');
    query.addOrderBy('talent.created_at', 'ASC');
    query.limit(5);
    return await query.getMany();
您可以向查询添加.limit(count)。 您的打字代码将是

  const query = await this.createQueryBuilder('category');
    query.leftJoinAndSelect('category.talent_worked', 'talent');
    query.leftJoinAndSelect('talent.working_categories', 'talentCategories');
    query.where('talent.isActive = :isActive AND talent.isBlocked = :isBlocked', { isActive: true, isBlocked: false});
    if (categoryId) query.andWhere('category.id = :categoryId', { categoryId });
    query.select([
        'category.id',
        'category.title',
        'talent.id',
        'talent.name',
        'talentCategories.id',
        'talentCategories.title',
    ]);
    query.orderBy('category.created_at', 'ASC');
    query.addOrderBy('talent.created_at', 'ASC');
    query.limit(5);
    return await query.getMany();

你的坦克是空的,但没用。有了这个限制,我们只限制了类别的数量,但我希望得到所有类别,并限制这方面的天赋。坦克为你的Answare,但它不起作用。有了这个限制,我们只限制了类别的数量,但我希望获得所有类别并限制这方面的天赋。你好,你解决了你的问题吗?你好,你解决了你的问题吗?