Fix runtime db_column mapping for foreign keys#139
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds end-to-end runtime support for custom ForeignKey database column names (db_column). Introduces model-field→DB-column resolution helpers, wires them into QueryBuilder and SqliterDB SQL generation (insert/get/update/join/filter), updates docs, demos and tests to validate behaviour. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client Code
participant DB as SqliterDB
participant QB as QueryBuilder
participant FK as FK Metadata
participant SQL as SQLite
Client->>DB: insert(Book, {'title':'T','author_id':123})
DB->>FK: get_model_field_db_column(Book, 'author_id')
FK-->>DB: 'author_ref'
DB->>QB: Build INSERT with mapped columns
QB->>SQL: INSERT INTO books ("title","author_ref") VALUES (?, ?)
SQL-->>QB: OK
QB-->>DB: result
Client->>DB: get(Book).filter(author_id=123)
DB->>QB: Build WHERE clause for 'author_id'
QB->>FK: resolve 'author_id' -> 'author_ref'
FK-->>QB: 'author_ref'
QB->>SQL: SELECT ... WHERE "author_ref" = ?
SQL-->>QB: rows
QB->>DB: map DB columns back to model fields
DB-->>Client: Book instance with .author_id
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/guide/foreign-keys/orm.md`:
- Around line 33-35: The sentence "By default the database column is also
`author_id`, but you can override the physical column name with
`db_column=...`." is missing a comma after "By default"; update the sentence in
the docs to read "By default, the database column is also `author_id` ..." so
the phrase "By default" is properly set off (look for the sentence containing
`author_id` and `db_column=...` in the ORM foreign keys paragraph).
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (12)
docs/api-reference/orm.mddocs/guide/foreign-keys/explicit.mddocs/guide/foreign-keys/orm.mddocs/tui-demo/orm.mdsqliter/model/foreign_key.pysqliter/query/query.pysqliter/sqliter.pysqliter/tui/demos/orm.pytests/test_debug_logging.pytests/test_foreign_keys.pytests/test_foreign_keys_orm.pytests/test_query.py
Summary
db_columnmapping for foreign keys across SQL generation pathsdb_columnbehavior across insert/get/filter/order/update and relationship query pathsdb_columnImplementation
get_model_field_db_column()insqliter/model/foreign_key.pysqliter/sqliter.pyfor insert/select/update SQL constructionsqliter/query/query.pyfor filters, ordering, joins, projections, and query updatesCloses #138
Summary by CodeRabbit
New Features
Documentation
Bug Fixes