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

fix: allow defining path type option as an array #1607

Merged
merged 2 commits into from
Nov 8, 2023

Conversation

mohamedjkr
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

When trying to declare an array schema path with additional options, an error is thrown due to invalid schema configuration.

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
    
class Profile extends Document {
  @Prop()
  name: string;
}

@Schema()
class Community extends Document {
  @Prop({ type: [Profile], required: true })
  profiles: Profile[];
}
export const communitySchema = SchemaFactory.createForClass(Community);

throws Invalid schema configuration: 'Profile' is not a valid type within the array 'profiles'.

The only way to fix it is by using @Prop({ type: [SchemaFactory.createForClass(Profile)], required: true }), or using @Prop([Profile]) while loosing the ability to pass additional options

Issue Number: #839

What is the new behavior?

The PR allows defining type option as an array of subdocuments so that @Prop({ type: [Profile], required: true }) would work as expected.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@kamilmysliwiec
Copy link
Member

Can you please rebase so the workflows execute as expected?

@mohamedjkr
Copy link
Contributor Author

mohamedjkr commented Mar 2, 2023

@kamilmysliwiec Rebased 👍 Let me know if you need any further changes before approving!

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

Successfully merging this pull request may close these issues.

2 participants