-
Notifications
You must be signed in to change notification settings - Fork 0
feat: v0.8.0 — typed projection (ScalarField enums, include-select, projected finders) #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f559e7b
3897c5b
68f9e7b
8216c27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -463,7 +463,16 @@ class RelationCompiler { | |||||||||||||||||||||||||||||||||||||||||||||||
| fieldToColumn[field.name] = field.columnName; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| for (final fieldName in selectedFields) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| // Always carry the primary key: the relation deserializer groups/dedupes | ||||||||||||||||||||||||||||||||||||||||||||||||
| // child rows by PK, so a select that omits it would silently drop the | ||||||||||||||||||||||||||||||||||||||||||||||||
| // relation's rows from the hydrated result. | ||||||||||||||||||||||||||||||||||||||||||||||||
| final effectiveFields = [ | ||||||||||||||||||||||||||||||||||||||||||||||||
| ...selectedFields, | ||||||||||||||||||||||||||||||||||||||||||||||||
| for (final pk in model.primaryKeys) | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (!selectedFields.contains(pk.name)) pk.name, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| for (final fieldName in effectiveFields) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+466
to
+475
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win PK-preservation fix leaks into base-model
Scope the PK-force to relation calls only, using the already-available 🛡️ Proposed fix- // Always carry the primary key: the relation deserializer groups/dedupes
- // child rows by PK, so a select that omits it would silently drop the
- // relation's rows from the hydrated result.
- final effectiveFields = [
- ...selectedFields,
- for (final pk in model.primaryKeys)
- if (!selectedFields.contains(pk.name)) pk.name,
- ];
+ // Relation rows are grouped/deduped by PK during hydration, so a
+ // relation-nested select that omits it would silently drop rows. This
+ // only applies to relation-nested selects (relationPath != null); the
+ // base model's own select is returned as-is with no such dedup step.
+ final effectiveFields = relationPath != null
+ ? [
+ ...selectedFields,
+ for (final pk in model.primaryKeys)
+ if (!selectedFields.contains(pk.name)) pk.name,
+ ]
+ : selectedFields;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| // Get actual column name (may differ from field name) | ||||||||||||||||||||||||||||||||||||||||||||||||
| final columnName = fieldToColumn[fieldName] ?? fieldName; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Guard against zero-scalar-field models.
If
model.fields.where((f) => !f.isRelation)is empty (a model with only relation fields),casesis''and the generated source isenum ${model.name}ScalarField {\n;\n ... }— an enum with no declared instances, which is invalid Dart (an enum must declare at least one instance). This would break codegen for that model's entire file.🛡️ Proposed guard
Spec _buildScalarFieldEnum(PrismaModel model) { final scalars = model.fields.where((f) => !f.isRelation).toList(); + if (scalars.isEmpty) { + return Code(''' +/// Scalar fields of ${model.name} for typed projection. +/// (${model.name} has no scalar fields.) +enum ${model.name}ScalarField { none(''); const ${model.name}ScalarField(this.fieldName); final String fieldName; } +'''); + } final cases = scalars📝 Committable suggestion
🤖 Prompt for AI Agents