Использование loopback и loopback sdkbuilder для получения значения базы данных
{
"name": "sdsCorpus",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "Number",
"required": true
},
"version": {
"type": "string",
"required": true
},
"lectureInfo": {
"type": "string"
},
"corpus": {
"type": "string"
},
"depth": {
"type": "string"
}
},
"validations": [],
"relations": {
"sdsvermap": {
"type": "belongsTo",
"model": "sdsVerMap",
"foreignKey": "id"
}
},
"acls": [],
"methods": {}
}
Это файл модели sdsCourpus
{
"name": "sdsModel",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "Number",
"required": true
},
"lectureInfo": {
"type": "string"
},
"leaderTalk": {
"type": "string"
},
"programId": {
"type": "string"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
Это файл модели sdsModel
{
"name": "sdsVerMap",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "Number"
},
"createdAt": {
"type": "date"
},
"createdId": {
"type": "string"
},
"filePath": {
"type": "string"
},
"corpusFileName": {
"type": "string"
},
"sdsDate": {
"type": "date"
},
"version": {
"type": "string"
}
},
"validations": [],
"relations": {
"sdsmodel": {
"type": "belongsTo",
"model": "sdsModel",
"foreignKey": "id"
}
},
"acls": [],
"methods": {}
}
Это файл модели sdsVerMap
import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core';
import { MatPaginator, MatSort, MatTableDataSource, MatIconRegistry } from '@angular/material';
import { SdsVerMapApi, SdsModelApi } from './core/sdk/services/custom';
@Component({
selector: 'app-root',
styleUrls: ['./app.component.css'],
templateUrl: './app.component.html'
})
export class AppComponent implements AfterViewInit {
displayedColumns = ['lectureInfo', 'leaderTalk', 'version', 'createdAt', 'modifiedView'];
data: SdsData[] = [];
dataSource = null;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
constructor(public sdsVerMapSetApi: SdsVerMapApi, public sdsModelApi: SdsModelApi ) {
this.getData();
}
getData() {
this.data = [];
this.sdsVerMapSetApi.find().subscribe(
result => {
for (let i = 0; i < result.length; i++) {
this.addData( {
version: result[i]['version'],
createdAt: result[i]['createdAt']
//I want add code in here
//select a.lectureInfo,a.leaderTalk,b.version,b.createdAt
//from sdsModel a,sdsVerMap b
//where a.id = b.sdsModel_id;
}
, i);
}
this.setData();
}
);
}
addData(dataSlice, idx) {
this.data[idx] = dataSlice;
}
setData() {
this.dataSource = new MatTableDataSource<SdsData>(this.data);
}
ngAfterViewInit() {
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
applyFilter(filterValue: string) {
filterValue = filterValue.trim(); // Remove whitespace
filterValue = filterValue.toLowerCase(); // Datasource defaults to lowercase matches
this.dataSource.filter = filterValue;
}
}
export interface SdsData {
lectureInfo: string;
leaderTalk: string;
version: string;
createdAt: string;
}
Это app.componet.ts. Я хочу получить следующее значение: выберите a.lectureInfo, a.leaderTalk, b.version,b.createdAt из sdsModel a,sdsVerMap b, где a.id = b.sdsModel_id;
Я не знаю, как использовать foreignkey для значения в другой модели // Я использую Anuglar.io looback-sdk-builder loopback, mysql