2
私はobjection.js文書ではっきりと見つけられなかった疑いがあります。私のような新しい国挿入したいObjection.jsに多対多の余分なフィールドを挿入します
export class Language extends BaseId {
name: string;
static tableName = 'Languages';
static jsonSchema = {
type: 'object',
required: ['name'],
properties: {
name: { type: 'string', minLength: 1, maxLength: 80 }
}
};
}
export class Country extends BaseId {
name: string;
languages: Language[];
static tableName = 'Countries';
static jsonSchema = {
type: 'object',
required: ['name'],
properties: {
name: { type: 'string', minLength: 1, maxLength: 120 }
}
};
static relationMappings: RelationMappings = {
languages: {
relation: Model.ManyToManyRelation,
modelClass: Language,
join: {
from: 'Countries.id',
through: {
from: 'CountriesLanguages.country_id',
to: 'CountriesLanguages.language_id',
extra: ['oficial']
},
to: 'Languages.id'
}
}
};
}
: は、私は、次の2つのモデルを持っているあなたが見ることができるように
{
name: "Country Name",
languages: [
{ id: 1, official: true },
{ id: 2, official: true },
{ id: 3, official: false }
]
}
を、私は私がしたい、新しい言語を作成する必要はありません余分なプロパティを持つ参照を追加するだけです。私は関係を持って国を作りたいだけです。 そのようなものを挿入する正しい方法は何ですか?私はドキュメントを見つけることができませんでしたが、言語を作成する方法を見つけました。
ありがとうございます!