Hasty Briefsbeta

Bilingual

SQLAlchemy 2 In Practice - Chapter 3 - One-To-Many Relationships

a day ago
  • This chapter covers one-to-many relationships in SQLAlchemy 2, focusing on moving duplicate data (like manufacturers) to separate tables.
  • It explains the implementation of a one-to-many relationship using foreign keys and SQLAlchemy ORM relationship attributes for transparent navigation.
  • The chapter demonstrates updating an importer script to handle separate Manufacturer and Product models, and shows how to query across these tables using joins.
  • It discusses relationship loaders (lazy vs. eager loading), specifically the 'select' default and 'joined' loader, and their impact on database performance.
  • The section on cascades covers deletion behavior, including 'all, delete-orphan' for automatic deletion of related products when a manufacturer is removed.
  • Exercises at the end provide practice with one-to-many queries, such as finding products by manufacturer or manufacturers with specific criteria.