पाठ 34 / 35

Common Interview and Exam Questions

यह पाठ अभी हिंदी में अनुवादित नहीं है, इसलिए अंग्रेज़ी में दिखाया जा रहा है।

Answer the ORM questions that come up most in interviews and viva exams, with short, precise model answers.

लेखक: · 15 साल से वेब डेवलपर

Questions you should be able to answer in two minutes

What is an ORM and what are its drawbacks? It maps objects to tables and generates SQL; drawbacks are hidden queries, N+1 risk, weaker control over complex SQL and a learning curve. What is the N+1 problem? One query for a list plus one per item; fix with eager loading or batching. Lazy vs eager loading? Eager loads relations up front with a join or extra query; lazy loads on first access, convenient but prone to N+1. Why migrations instead of sync? Reviewable, ordered, repeatable, safe in production. How do you prevent SQL injection with an ORM? Use the query API or parameterised raw queries; never concatenate input; whitelist identifiers. Optimistic vs pessimistic locking? Version check on write versus row lock on read. Active Record vs Data Mapper? Models that save themselves versus separate repositories that persist plain entities. When would you skip the ORM? Complex reports, bulk operations and database-specific features.

Viva voce rules

In a viva, the examiner checks if you understand, not if you memorised. Answer in three beats: define the term, give a small example, state the trade-off. 'N+1 is... for example listing posts with authors... fixed by include, at the cost of a heavier single query.'

Draw the SQL

When asked about an ORM behaviour, write the SQL it produces on the whiteboard. Showing that include became a LEFT JOIN or an IN (...) query instantly proves you understand what happens below the abstraction.

त्वरित जाँच: In the Active Record pattern, which statement is true?

  • Entities are plain objects and a separate repository saves them
  • Model instances carry their own persistence methods such as save() and destroy()
  • There is no database involved
  • Only raw SQL may be used
Answer

Model instances carry their own persistence methods such as save() and destroy() — Active Record puts persistence on the model instance itself, as in Sequelize or TypeORM entities extending BaseEntity. Data Mapper keeps persistence in repositories.