我试图通过sls框架将Objection.js与AWS Lambda结合使用。现在,我收到一个错误“无服务器:故障:Person.relationMappings.articles:找不到模块'/ Article'”。
完整回购:https://github.com/edlgg/Veritas-Back
相关代码:
// handler.ts
import { APIGatewayEvent, Context, Handler, Callback } from 'aws-lambda'
import User from '../src/models/User'
export const hello : Handler = async (event : APIGatewayEvent, context : Context, cb : Callback) => {
const users = await User.query().findById(1).eager('commentReactions')
const response = {
statusCode: 200,
body: JSON.stringify({
message: users
})
}
cb(null, response)
}
//User model
import { Model, RelationMappings } from 'objection'
import CommentReaction from './CommentReaction'
const Knex = require('knex')
const connection = require('../knexfile')
const knexConnection = Knex(connection.production)
Model.knex(knexConnection)
const fs = require('fs');
fs.readdirSync(__dirname).forEach((file: any) => {
console.log(file);
})
export default class Person extends Model {
readonly id!: number
firstName?: string
lastName?: string
commentReactions?: CommentReaction[]
static tableName = 'Users'
static jsonSchema = {
type: 'object',
required: [
'id',
'fistName',
'lastName'
],
properties: {
id: { type: 'integer' },
firstName: { type: 'string', minLength: 1, maxLength: 255 },
lastName: { type: 'string', minLength: 1, maxLength: 255 }
}
}
static modelPaths = [__dirname]
static relationMappings: RelationMappings = {
commentReactions: {
relation: Model.HasManyRelation,
modelClass: __dirname + 'CommentReaction',
join: {
from: 'Users.id',
to: 'CommentReactions.userId'
}
}
}
}