8. Interview Questions- ORM Examples
1. What is the Versioned Rows example about?
2. How are versioned rows implemented in SQLAlchemy?
3. What is the purpose of the Adjacency List example?
4. How is an adjacency list modeled in SQLAlchemy ORM?
class Node(Base):
parent_id = Column(ForeignKey('node.id'))
parent = relationship("Node", remote_side='Node.id', backref="children")5. What does remote_side do in a self-referential relationship?
remote_side do in a self-referential relationship?6. What is the "horizontal table inheritance" example about?
7. What is a composite type in SQLAlchemy?
8. How do you map a composite object to multiple columns?
9. What is the benefit of using composite() in ORM models?
composite() in ORM models?10. How is custom column typing demonstrated in the examples?
11. What is a TypeDecorator?
TypeDecorator?12. What does the process_bind_param() method in TypeDecorator do?
process_bind_param() method in TypeDecorator do?13. What is the process_result_value() method used for?
process_result_value() method used for?14. How does the examples page demonstrate many-to-many relationships with extra data?
15. What is the advantage of the association object pattern over a plain secondary table?
secondary table?16. How is a dictionary-of-values pattern implemented in SQLAlchemy ORM?
17. What is an example use case for the dictionary-of-values pattern?
18. What pattern is shown to build polymorphic identity manually?
19. What is the purpose of the “attribute events” used in examples?
20. Can these examples be used as templates for production systems?
21. How do you model a many-to-many relationship with extra fields like timestamps?
22. In the association object pattern, how are the foreign key links usually defined?
23. How do you define bidirectional relationships in an association object pattern?
24. Can association objects be used with association_proxy?
association_proxy?25. What is the benefit of using a self-referential foreign key in a tree structure (Adjacency List)?
26. How can you retrieve the descendants of a node in an adjacency list pattern?
27. How do you store hierarchical paths in the Adjacency List example?
28. What is a “composite key” in the composite pattern example?
29. What method must be implemented in a composite type class?
30. Can you use composite columns in queries?
31. In the versioned rows example, why is the before_update event important?
before_update event important?32. What fields are typically added to a versioned history table?
33. How do you identify which object versions belong to which source row in versioned history?
34. How can you use TypeDecorator for encrypted fields?
TypeDecorator for encrypted fields?35. What’s a real-world use case for using a custom type with TypeDecorator?
TypeDecorator?36. What does impl refer to in a TypeDecorator subclass?
impl refer to in a TypeDecorator subclass?37. Can a TypeDecorator return a different Python type than the one stored in the DB?
TypeDecorator return a different Python type than the one stored in the DB?38. In the horizontal inheritance example, why is a union query used?
39. What’s a drawback of horizontal table inheritance?
40. How does SQLAlchemy support versioning without requiring database triggers?
41. How can you model a dynamic dictionary of user preferences in SQLAlchemy?
42. What is the main use case for the "dictionary of values" pattern?
43. In a composite class, how do you make sure SQLAlchemy detects changes?
44. What is one advantage of using association_proxy over accessing relationships directly?
association_proxy over accessing relationships directly?45. How do you handle bidirectional updates between parent and child in a self-referential hierarchy?
46. Why is composite() preferable over multiple fields in some designs?
composite() preferable over multiple fields in some designs?47. In the versioned rows example, why might you use a separate version number column?
48. Can TypeDecorator be used with column-level constraints like unique=True?
TypeDecorator be used with column-level constraints like unique=True?49. How would you write a query to fetch the latest version of a versioned row?
50. What is one SQLAlchemy feature that simplifies working with tree-structured data?
Last updated