Code Monkey home page Code Monkey logo

Comments (9)

hardyscc avatar hardyscc commented on May 17, 2024 2

@MRdgz I just tested the factory should only called once,
also the model should be passed as the second arg, so please try this example if this works for u

export const GameSchemaDef = {
  id: String,
  state: String,
}
@Module({
  imports: [
    DynamooseModule.forFeatureAsync([
      {
        name: 'User',
        useFactory: () => UserSchema,
      },
      {
        name: 'Game',
        useFactory: (_, model) => new Schema({ ...GameSchemaDef, user: model }),
        inject: ['UserModel'],
      },
    ]),
]})

from nestjs-dynamoose.

elijahmg avatar elijahmg commented on May 17, 2024 1

Sorry for miss-leading message, but the last example is worked for me

from nestjs-dynamoose.

hardyscc avatar hardyscc commented on May 17, 2024

@MRdgz i don't know this will work or not, but u could have a try.

import { model, Schema, THIS } from 'dynamoose';

export const UserSchema = new Schema({
  id: String,
  name: String,
  parent: THIS,
});

export const GameSchema = new Schema({
  id: String,
  state: String,
  user: model('User', UserSchema),
});
import { UserSchema, GameSchema } from './schema'

@Module({
  imports: [
    DynamooseModule.forFeature([
      {
        name: 'User',
        schema: UserSchema,
      },
      {
        name: 'Game',
        schema: GameSchema,
      },
    ]),
  ],
  ...
})

from nestjs-dynamoose.

MRdgz avatar MRdgz commented on May 17, 2024

Thanks, I'll let you know if this works!

from nestjs-dynamoose.

MRdgz avatar MRdgz commented on May 17, 2024

It didn't work. At compile time, an UnhandledPromiseRejectionWarning: ConfigError: Missing region in config warning is shown. If I attempt to save anyways, it does store into the game table as

{ 
   "id": 1,
   "state": "loss",
   "user" : {
      "id": 33,
   }
}

But when fetching the record and executing the await game.populate() it just hangs.

from nestjs-dynamoose.

MRdgz avatar MRdgz commented on May 17, 2024

I've also tried the following with GameSchema(model).getSchema() returning a schema instance. Using this method. It no longer generates the warning from above but says that user is an unknown property when trying to store new information. I did notice that during compile, the factory is running twice. The first has model as undefined, and the second time model is actually defined.

@Module({
  imports: [
    DynamooseModule.forFeatureAsync([
      {
        name: 'User',
        useFactory: () => UserSchema,
      },
      {
        name: 'Game',
        useFactory: (model) => new GameSchema(model).getSchema(),
        inject: ['UserModel'],
      },
    ]),
]})

from nestjs-dynamoose.

elijahmg avatar elijahmg commented on May 17, 2024

@hardyscc @MRdgz will join here. Have same problem right now. I tried both solutions, and getting same error as above ConfigError: Missing region in config

from nestjs-dynamoose.

MRdgz avatar MRdgz commented on May 17, 2024

Thank you, the solution above also worked for me! I will close the issue now! 😄

from nestjs-dynamoose.

nguyenjk avatar nguyenjk commented on May 17, 2024

Thank you, the solution above also worked for me! I will close the issue now! 😄

@MRdgz do you have working sample? I tried the same but got error at compile time Type 'SchemaSettings' is missing the following properties from type 'AttributeDefinition[]

from nestjs-dynamoose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.