Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.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
Javascript 如何使用Include键在环回v4中建立关系_Javascript_Node.js_Mongodb_Loopbackjs_Loopback4 - Fatal编程技术网

Javascript 如何使用Include键在环回v4中建立关系

Javascript 如何使用Include键在环回v4中建立关系,javascript,node.js,mongodb,loopbackjs,loopback4,Javascript,Node.js,Mongodb,Loopbackjs,Loopback4,我遵循这些步骤,然后尝试使用include获取数据,但得到了500 500 Error: Invalid "filter.include" entries: {"relation":"ranks"} 我想得到的是游戏对象及其相关等级 排名模型 import { Entity, model, property, belongsTo } from '@loopback/repository'; import { Game, GameWithRelations } from './game.mod

我遵循这些步骤,然后尝试使用
include
获取数据,但得到了500

500 Error: Invalid "filter.include" entries: {"relation":"ranks"}

我想得到的是游戏对象及其相关等级

排名模型

import { Entity, model, property, belongsTo } from '@loopback/repository';
import { Game, GameWithRelations } from './game.model';

@model({ settings: { strict: 'filter' } })
export class Rank extends Entity {
  @property({
    type: 'string',
    id: true,
  })
  id?: string;

  @property({
    type: 'string',
  })
  name?: string;

  @property({
    type: 'string',
  })
  shortName?: string;

  @property({
    type: 'string',
  })
  avatar?: string;

  @belongsTo(() => Game)
  gameId: string;

  constructor(data?: Partial<Rank>) {
    super(data);
  }
}

export interface RankRelations {
  game?: GameWithRelations;
}

export type RankWithRelations = Rank & RankRelations;
import { Entity, model, property, embedsMany, hasMany } from '@loopback/repository';
import { Rank, RankWithRelations } from './rank.model';
import { HasMany } from 'loopback-datasource-juggler';

@model({ settings: { strict: 'filter' } })
export class Game extends Entity {
  @property({
    type: 'string',
    id: true,
  })
  id?: string;

  @property({
    type: 'string',
    required: true,
  })
  name?: string;

  @property({
    type: 'string',
  })
  shortName?: string;

  @property({
    type: 'string',
  })
  avatar?: string;

  @hasMany<Rank>(() => Rank, { keyTo: 'gameId' })
  ranks?: Rank[];

  constructor(data?: Partial<Game>) {
    super(data);
  }
}

export interface GameRelations {
}

export type GameWithRelations = Game & GameRelations;
从'@loopback/repository'导入{Entity,model,property,belongsTo};
从“/Game.model”导入{Game,GameWithRelations};
@模型({settings:{strict:'filter'}})
导出类秩扩展实体{
@财产({
键入:“字符串”,
id:是的,
})
id?:字符串;
@财产({
键入:“字符串”,
})
名称?:字符串;
@财产({
键入:“字符串”,
})
shortName?:字符串;
@财产({
键入:“字符串”,
})
阿凡达?:字符串;
@属于(()=>游戏)
配子体:字符串;
构造函数(数据?:部分){
超级(数据);
}
}
导出接口关系{
游戏?:游戏与关系;
}
导出类型RankWithRelations=等级和等级关系;
游戏模式

import { Entity, model, property, belongsTo } from '@loopback/repository';
import { Game, GameWithRelations } from './game.model';

@model({ settings: { strict: 'filter' } })
export class Rank extends Entity {
  @property({
    type: 'string',
    id: true,
  })
  id?: string;

  @property({
    type: 'string',
  })
  name?: string;

  @property({
    type: 'string',
  })
  shortName?: string;

  @property({
    type: 'string',
  })
  avatar?: string;

  @belongsTo(() => Game)
  gameId: string;

  constructor(data?: Partial<Rank>) {
    super(data);
  }
}

export interface RankRelations {
  game?: GameWithRelations;
}

export type RankWithRelations = Rank & RankRelations;
import { Entity, model, property, embedsMany, hasMany } from '@loopback/repository';
import { Rank, RankWithRelations } from './rank.model';
import { HasMany } from 'loopback-datasource-juggler';

@model({ settings: { strict: 'filter' } })
export class Game extends Entity {
  @property({
    type: 'string',
    id: true,
  })
  id?: string;

  @property({
    type: 'string',
    required: true,
  })
  name?: string;

  @property({
    type: 'string',
  })
  shortName?: string;

  @property({
    type: 'string',
  })
  avatar?: string;

  @hasMany<Rank>(() => Rank, { keyTo: 'gameId' })
  ranks?: Rank[];

  constructor(data?: Partial<Game>) {
    super(data);
  }
}

export interface GameRelations {
}

export type GameWithRelations = Game & GameRelations;
从'@loopback/repository'导入{Entity,model,property,embedsMany,hasMany};
从“/Rank.model”导入{Rank,RankWithRelations};
从“环回数据源处理程序”导入{HasMany};
@模型({settings:{strict:'filter'}})
导出类游戏扩展实体{
@财产({
键入:“字符串”,
id:是的,
})
id?:字符串;
@财产({
键入:“字符串”,
要求:正确,
})
名称?:字符串;
@财产({
键入:“字符串”,
})
shortName?:字符串;
@财产({
键入:“字符串”,
})
阿凡达?:字符串;
@有许多(()=>等级,{keyTo:'gameId'})
等级?:等级[];
构造函数(数据?:部分){
超级(数据);
}
}
导出接口关系{
}
导出类型GameWithRelations=游戏和游戏关系;
游戏控制器

// in this method
// 500 Error: Invalid "filter.include" entries: {"relation":"ranks"}

 @get('/games/{id}')
  async findById(@param.path.string('id') id: string): Promise<Game> {
    return await this.gameRepository.findById(id, { include: [{ relation: 'ranks' }] });
  }
//在这个方法中
//500错误:无效的“筛选器。包括”条目:{“关系”:“等级”}
@获取('/games/{id}'))
异步findById(@param.path.string('id')id:string):承诺{
return wait this.gameRepository.findById(id,{include:[{relation:'ranks'}]});
}

请使用
DEBUG=loopback:repository:relationshippers
运行应用程序,这样您将收到一条调试消息,解释为什么
筛选。include
条目被拒绝

您可以在此处找到生成错误消息的代码:

最可能的原因:您的
GameRepository
没有为
ranks
关系注册任何InclusionResolver。

请参阅我们的
待办事项列表
示例,了解如何注册包含解析器。交叉过帐来源:


很高兴得到你的答复。当我更新环回包时,
inclusionResolver
消失了。谢谢