Can you use dynamoose to have multiple models share a single table? Here are two models that I have where I want them being saved in the same table and differentiate them by their type
hash key and id
range key.
const Courses = dynamoose.model(
process.env.CONTENT_TABLE,
new dynamoose.Schema(
{
id: { type: String, rangeKey: true },
type: { type: String, hashKey: true },
department: { type: String },
description: { type: String },
image: { type: String },
name: { type: String },
},
{
throughput: 1,
timestamps: true
}
),
{ update: true }
);
const Teachers = dynamoose.model(
process.env.CONTENT_TABLE,
new dynamoose.Schema(
{
id: { type: String, rangeKey: true },
type: { type: String, hashKey: true },
picture: { type: String },
name: { type: String },
bio: { type: String }
},
{
throughput: 1,
timestamps: true
}
),
{ update: true }
);
These are the methods that I use. I can tell in console.logging the args parameters have what I expect going into the new ...
. The return statement from thenew Course
or new Teachers
functions have all the parameters that I added but they don't actually end up in the database. Why is that?
create: ({ args, context }) =>
new Courses({
id: shortid.generate(),
type: course,
...args
}).save()
create: ({ args, context }) => {
console.log(args);
return new Teachers({
id: shortid.generate(),
type: teacher,
...args
}).save();