# Doctrine ขั้นสูง (Symfony) > migration, lifecycle callback, event, การสืบทอด, custom type, การเพิ่มประสิทธิภาพ - 24 คำถามสัมภาษณ์ - Mid-Level - [คำถามสัมภาษณ์: Symfony](https://sharpskill.dev/th/technologies/symfony/interview-questions.md) ## 1. คำสั่งใดที่สร้าง migration ของ Doctrine ใหม่ใน Symfony? **คำตอบ** คำสั่ง doctrine:migrations:diff จะเปรียบเทียบ schema ปัจจุบันของฐานข้อมูลกับ metadata ของ entity และสร้าง migration ที่มีส่วนต่างขึ้นมาโดยอัตโนมัติ นี่คือวิธีที่แนะนำในการสร้าง migration เนื่องจากช่วยหลีกเลี่ยงข้อผิดพลาดที่เกิดจากการทำด้วยมือและรับประกันความสอดคล้องระหว่างโค้ดและฐานข้อมูล ## 2. lifecycle callback ใดที่ถูกเรียกใช้ก่อนที่ entity จะถูกแทรกเข้าไปในฐานข้อมูล? **คำตอบ** PrePersist callback จะถูกเรียกใช้ก่อนที่ entity ใหม่จะถูก persist ลงในฐานข้อมูล นี่คือตำแหน่งที่เหมาะที่สุดในการกำหนดค่าเริ่มต้น เช่น timestamp ของการสร้าง หรือสร้างตัวระบุที่ไม่ซ้ำกันก่อนการแทรกข้อมูล ## 3. จะเปิดใช้งาน lifecycle callback บน entity ของ Doctrine ได้อย่างไร? **คำตอบ** ต้องเพิ่ม attribute HasLifecycleCallbacks ลงในคลาส entity เพื่อเปิดใช้งาน callback หากไม่มี attribute นี้ เมธอดที่ระบุด้วย PrePersist, PostUpdate และ callback อื่น ๆ จะไม่ถูก Doctrine เรียกใช้เลย ## มีอีก 21 คำถาม - คำสั่งใดที่รัน migration ที่ค้างอยู่ทั้งหมดใน Doctrine? - ควรใช้ callback ของ Doctrine ใดเพื่ออัปเดตฟิลด์ 'updatedAt' โดยอัตโนมัติทุกครั้งที่มีการแก้ไข? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Symfony อื่นๆ - [PHP สมัยใหม่ (8.1+)](https://sharpskill.dev/th/technologies/symfony/interview-questions/php-modern-features.md): 20 คำถาม, Junior - [พื้นฐาน Symfony](https://sharpskill.dev/th/technologies/symfony/interview-questions/symfony-basics.md): 25 คำถาม, Junior - [Routing & Controllers](https://sharpskill.dev/th/technologies/symfony/interview-questions/routing-controllers.md): 20 คำถาม, Junior - [Twig & Templates](https://sharpskill.dev/th/technologies/symfony/interview-questions/twig-templates.md): 20 คำถาม, Junior - [พื้นฐาน Doctrine ORM](https://sharpskill.dev/th/technologies/symfony/interview-questions/doctrine-orm-basics.md): 25 คำถาม, Junior - [ฟอร์ม Symfony](https://sharpskill.dev/th/technologies/symfony/interview-questions/forms.md): 22 คำถาม, Junior - [การตรวจสอบความถูกต้องของข้อมูล](https://sharpskill.dev/th/technologies/symfony/interview-questions/validation.md): 18 คำถาม, Junior - [Dependency Injection & Services](https://sharpskill.dev/th/technologies/symfony/interview-questions/dependency-injection.md): 24 คำถาม, Mid-Level - [Security & Authentication](https://sharpskill.dev/th/technologies/symfony/interview-questions/security-authentication.md): 26 คำถาม, Mid-Level - [API Platform](https://sharpskill.dev/th/technologies/symfony/interview-questions/api-platform.md): 22 คำถาม, Mid-Level - [Serializer Component](https://sharpskill.dev/th/technologies/symfony/interview-questions/serializer.md): 20 คำถาม, Mid-Level - [Events & Event Subscribers](https://sharpskill.dev/th/technologies/symfony/interview-questions/events-subscribers.md): 20 คำถาม, Mid-Level - [Console & Commands](https://sharpskill.dev/th/technologies/symfony/interview-questions/console-commands.md): 18 คำถาม, Mid-Level - [Messenger Component](https://sharpskill.dev/th/technologies/symfony/interview-questions/messenger.md): 22 คำถาม, Mid-Level - [HTTP Client](https://sharpskill.dev/th/technologies/symfony/interview-questions/http-client.md): 18 คำถาม, Mid-Level - [Cache & ประสิทธิภาพ](https://sharpskill.dev/th/technologies/symfony/interview-questions/cache.md): 20 คำถาม, Mid-Level - [Workflow Component](https://sharpskill.dev/th/technologies/symfony/interview-questions/workflow.md): 18 คำถาม, Mid-Level - [Testing Symfony](https://sharpskill.dev/th/technologies/symfony/interview-questions/testing.md): 22 คำถาม, Mid-Level - [Mailer Component](https://sharpskill.dev/th/technologies/symfony/interview-questions/mailer.md): 16 คำถาม, Mid-Level - [การแปลและ i18n](https://sharpskill.dev/th/technologies/symfony/interview-questions/translations.md): 16 คำถาม, Mid-Level - [EasyAdmin Bundle](https://sharpskill.dev/th/technologies/symfony/interview-questions/easyadmin.md): 18 คำถาม, Mid-Level - [สถาปัตยกรรม Symfony](https://sharpskill.dev/th/technologies/symfony/interview-questions/architecture-patterns.md): 24 คำถาม, Senior - [ประสิทธิภาพและการเพิ่มประสิทธิภาพ](https://sharpskill.dev/th/technologies/symfony/interview-questions/performance-optimization.md): 22 คำถาม, Senior - [ความปลอดภัยขั้นสูง](https://sharpskill.dev/th/technologies/symfony/interview-questions/security-advanced.md): 22 คำถาม, Senior - [Custom Bundles](https://sharpskill.dev/th/technologies/symfony/interview-questions/custom-bundles.md): 20 คำถาม, Senior - [Microservices ด้วย Symfony](https://sharpskill.dev/th/technologies/symfony/interview-questions/microservices.md): 22 คำถาม, Senior - [Real-time & WebSockets](https://sharpskill.dev/th/technologies/symfony/interview-questions/real-time.md): 18 คำถาม, Senior - [Deployment & DevOps](https://sharpskill.dev/th/technologies/symfony/interview-questions/deployment-devops.md): 20 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/symfony/interview-questions/doctrine-advanced