Bird
0
0

Given this schema snippet:

medium📝 component behavior Q13 of 15
NestJS - Database with Prisma
Given this schema snippet:
@Schema()
export class Book {
  @Prop()
  author: string;

  @Prop({ required: true })
  pages: number;
}

What happens if you try to save a Book without pages?
AThe save will throw a syntax error
BThe save will succeed and <code>pages</code> will be undefined
CThe save will succeed and <code>pages</code> will default to 0
DThe save will fail because <code>pages</code> is required
Step-by-Step Solution
Solution:
  1. Step 1: Understand the required: true option

    The pages property is marked as required, so it must be provided when saving.
  2. Step 2: Predict behavior when missing required property

    Omitting pages causes validation to fail and the save operation to be rejected.
  3. Final Answer:

    The save will fail because pages is required -> Option D
  4. Quick Check:

    Required props must be present [OK]
Quick Trick: Required props block save if missing [OK]
Common Mistakes:
  • Assuming missing required props default silently
  • Confusing validation errors with syntax errors
  • Ignoring the required option in @Prop()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes