Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] No way to retrieve SchemaDefinition from Schema #1595

Open
6 tasks done
lmanerich opened this issue Apr 28, 2023 · 4 comments
Open
6 tasks done

[BUG] No way to retrieve SchemaDefinition from Schema #1595

lmanerich opened this issue Apr 28, 2023 · 4 comments

Comments

@lmanerich
Copy link
Contributor

lmanerich commented Apr 28, 2023

Summary:

In Dynamoose V2 it was possible to created nested schema relations by using

MySchema.schemaObject

In V3 this attribute is no longer available and I found no way to getting the SchemaDefinition from a Schema object.

Code sample:

Schema

export const CompanySchema = new dynamoose.Schema({
    name: {
        required: true,
        type: String,
    }
});

export const UserSchema = new dynamoose.Schema({
    name: {
        required: true,
        type: String,
    },
    company: {
        type: Object,
        schema: CompanySchema.schemaObject, // not available anymore and just using the Schema doesnt work
    },
});

Model

dynamoose.model('company', CompanySchema);
dynamoose.model('user', UserSchema);

General

//

Current output and behavior (including stack trace):

Error trying to update: TypeError: Cannot read properties of undefined (reading 'schema')
    at ...\node_modules\dynamoose\dist\Schema.js:967:50
    at Array.reduce (<anonymous>)

Expected output and behavior:

Nested schema definition loaded

Environment:

Operating System: Windows
Operating System Version: 11 Pro
Node.js version (node -v): 18
NPM version: (npm -v): v18.16.0
Dynamoose version: 3.2.0

Other information (if applicable):

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • I have searched the internet and Stack Overflow to ensure this issue hasn't been raised or answered before
  • I have tested the code provided and am confident it doesn't work as intended
  • I have filled out all fields above
  • I am running the latest version of Dynamoose
@lmanerich

This comment was marked as outdated.

@fishcharlie
Copy link
Member

@lmanerich I have hidden your last comment. Using undocumented properties, classes, methods/functions is HIGHLY discouraged. Please see https://dynamoosejs.com/other/FAQ#can-i-use-an-undocumented-property-class-method-or-function-in-dynamoose for more details.

You mention and just using the Schema doesnt work, but you don't give any detail about why that doesn't work. Can you provide me with more detail here? Is there an error that gets thrown? How doesn't it work?

@lmanerich
Copy link
Contributor Author

Hey @fishcharlie hope you are doing great.

Using the Schema object as schema reference

export const UserSchema = new dynamoose.Schema({
    name: {
        required: true,
        type: String,
    },
    company: {
        type: Object,
        schema: CompanySchema, // results in error
    },
});

results in the following error message

Error trying to update: TypeError: Cannot read properties of undefined (reading 'schema')
    at ...\node_modules\dynamoose\dist\Schema.js:967:50
    at Array.reduce (<anonymous>)

@ptejada
Copy link
Contributor

ptejada commented May 22, 2023

@lmanerich

It looks like you are just trying to reference another Model. If that is the case based on this documentation for the Model type, you should be able to do this

export const UserSchema = new dynamoose.Schema({
    name: {
        required: true,
        type: String,
    },
    company: CompanySchema
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants