# พื้นฐาน Doctrine ORM (Symfony) > Entities, annotations, EntityManager, repositories, DQL, QueryBuilder, relationships - 25 คำถามสัมภาษณ์ - Junior - [คำถามสัมภาษณ์: Symfony](https://sharpskill.dev/th/technologies/symfony/interview-questions.md) ## 1. Doctrine ORM ในบริบทของ Symfony คืออะไร? **คำตอบ** Doctrine ORM คือ Object-Relational Mapper ที่ช่วยให้สามารถจัดการข้อมูลในฐานข้อมูลผ่านอ็อบเจกต์ PHP ได้ มันทำให้ SQL query เป็นนามธรรมโดยการจัดเตรียมเลเยอร์อ็อบเจกต์ ทำให้โค้ดดูแลรักษาได้ง่ายขึ้นและพกพาข้ามระบบจัดการฐานข้อมูลต่าง ๆ ได้ มันเป็น ORM เริ่มต้นที่แนะนำให้ใช้กับ Symfony ## 2. ควรใช้ attribute ของ PHP 8 ตัวใดในการประกาศ class ให้เป็น entity ของ Doctrine? **คำตอบ** attribute #[ORM\Entity] ใช้เพื่อบอก Doctrine ว่า class PHP เป็น entity ที่ map ไปยังตารางในฐานข้อมูล attribute นี้แทนที่ annotations แบบคอมเมนต์ และเป็นส่วนหนึ่งของ namespace Doctrine\ORM\Mapping สามารถใช้ร่วมกับ repositoryClass เพื่อระบุ repository แบบกำหนดเองได้ ## 3. จะกำหนดคอลัมน์ที่เพิ่มค่าอัตโนมัติให้เป็น primary key ใน entity ของ Doctrine ได้อย่างไร? **คำตอบ** ในการกำหนด primary key ที่เพิ่มค่าอัตโนมัติ ต้องใช้ attributes สองตัวร่วมกัน ได้แก่ #[ORM\Id] เพื่อทำเครื่องหมายให้พร็อพเพอร์ตี้เป็นตัวระบุ และ #[ORM\GeneratedValue] เพื่อระบุว่าค่าจะถูกสร้างโดยฐานข้อมูลโดยอัตโนมัติ กลยุทธ์เริ่มต้นคือ AUTO ซึ่งจะเลือกวิธีที่เหมาะสมตาม DBMS ## มีอีก 22 คำถาม - ความแตกต่างระหว่าง persist() และ flush() ใน EntityManager คืออะไร? - ควรใช้ attribute ใดในการ map พร็อพเพอร์ตี้ string ไปยังคอลัมน์ VARCHAR ใน Doctrine? สมัครฟรี: 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 - [ฟอร์ม 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 - [Doctrine ขั้นสูง](https://sharpskill.dev/th/technologies/symfony/interview-questions/doctrine-advanced.md): 24 คำถาม, 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-orm-basics