2. Interview Questions- ORM Mapped Class Configuration
1. What are the two primary styles of ORM mapper configuration in SQLAlchemy?
2. What is the recommended approach for mapping in modern SQLAlchemy?
3. How do you declare a mapped class using declarative mapping?
class MyClass(Base):
__tablename__ = "my_table"
id: Mapped[int] = mapped_column(primary_key=True)4. How is table metadata associated with a declarative model?
5. What is imperative mapping?
6. What function is used for classical (imperative) mapping?
7. How do you define a mapped class using imperative mapping?
8. What is registry() in SQLAlchemy ORM?
registry() in SQLAlchemy ORM?9. How do you declare mixins in SQLAlchemy ORM?
10. What is the role of __mapper_args__?
__mapper_args__?11. What does __table__ signify in a mapped class?
__table__ signify in a mapped class?12. Can a single class be mapped to multiple tables?
13. How do you specify a custom primary key in declarative mapping?
14. How do mixins interact with __tablename__?
__tablename__?15. Can you define relationships in a mixin class?
16. What is a declarative registry?
17. What does __allow_unmapped__ = True do?
__allow_unmapped__ = True do?18. How can you override default behavior in class mappings?
19. What’s the difference between mapped_column() and Column()?
mapped_column() and Column()?20. How do you reflect a table for use in imperative mapping?
21. What does the eager_defaults mapper argument do?
eager_defaults mapper argument do?22. What is polymorphic_on used for in __mapper_args__?
polymorphic_on used for in __mapper_args__?23. What does polymorphic_identity signify in a mapped class?
polymorphic_identity signify in a mapped class?24. How do you specify ordering for a mapped class using __mapper_args__?
__mapper_args__?25. Can you use SQLAlchemy ORM without declaring a Base class?
Base class?26. What happens if two classes define the same __tablename__?
__tablename__?27. How do you create an abstract base class that isn’t mapped itself?
28. What does __abstract__ = True do?
__abstract__ = True do?29. What is the purpose of a mixin class in SQLAlchemy?
30. Can mixins contain foreign key relationships?
31. What is the difference between __tablename__ and __table__ in a model class?
__tablename__ and __table__ in a model class?32. How can you exclude a column from being mapped in a declarative class?
33. What is the use of declarative_mixin decorator?
declarative_mixin decorator?34. Can mixins override columns from the parent class?
35. How do you define joined-table inheritance in declarative mapping?
36. Can a model define __mapper_args__ without defining __tablename__?
__mapper_args__ without defining __tablename__?37. What is the impact of omitting Mapped[...] in a declarative field?
Mapped[...] in a declarative field?38. How do you ensure compatibility with Python static type checkers in SQLAlchemy?
39. What happens when registry().map_imperatively() is called more than once for the same class?
registry().map_imperatively() is called more than once for the same class?40. How does SQLAlchemy handle attribute name clashes between mixins and subclasses?
41. What is the function of __init__() in declarative models?
__init__() in declarative models?42. How does SQLAlchemy determine which attributes to map when using declarative mapping?
43. How can you control if a class should be mapped at runtime?
44. What happens if you declare a field with mapped_column() but forget Mapped[...]?
mapped_column() but forget Mapped[...]?45. Why is registry.metadata preferred in imperative mapping over standalone MetaData?
registry.metadata preferred in imperative mapping over standalone MetaData?46. How does SQLAlchemy know a class is "mapped"?
47. What error will you get if you access .metadata on a model class that isn't properly mapped?
.metadata on a model class that isn't properly mapped?48. Can you modify __mapper_args__ dynamically at runtime?
__mapper_args__ dynamically at runtime?49. How does SQLAlchemy differentiate between regular attributes and mapped columns in declarative mapping?
50. What is the impact of assigning __table_args__ in a declarative class?
__table_args__ in a declarative class?Previous1. Interview Questions -SQLAlchemy ORMNext3. Interview Questions- Relationship Configuration
Last updated