Adds a regression test for nested collection predicates in access
policies generating valid SQL (issue #2538).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When creating a model with a nested many-to-many `connect`, the join table
insert triggered an update-policy check on the just-created entity. Because
the connection doesn't exist yet at check time, relation-based policies
(e.g. `parents?[id == auth().id]`) always evaluated to false, causing a
spurious "not updatable" error.
Fix by embedding a lightweight marker in the insert query's end-modifier
comment so the policy handler can identify the newly-created side and skip
its circular update check. The connected side's update policy is still
enforced. Adds regression test for issue #2531.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The generated schema previously used `as const` on entire model/enum/typeDef
objects, causing TypeScript to deeply infer literal types for all nested
properties. This is unnecessary for `attributes`, `default`, and `foreignKeyFor`
which are only used at runtime, not in CRUD type computations.
Changes:
- Add type assertions (`as readonly AttributeApplication[]`, `as FieldDefault`,
`as readonly string[]`) to prevent deep const inference on these properties
- Extract `FieldDefault` type alias from `FieldDef` for cleaner generated code
- Change `FieldHasDefault` to use key existence check (`'default' extends keyof`)
instead of value type check, enabling the `default` widening
- Conditionally import `AttributeApplication` and `FieldDefault` only when used
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Change DataType enum from TEXT/NUMBER to DataText/DataNumber
- Remove explicit dataType field from test as it's auto-set by delegate discriminator
- Fixes MySQL test failure: delegate discriminators must use model names
Co-authored-by: Yiming Cao <ymc9@users.noreply.github.com>
The test was failing on MySQL because the dataType enum field was required
but not provided when creating DataText records. MySQL is stricter about
enum validation than SQLite, causing 'Data truncated for column' errors.
Co-authored-by: Yiming Cao <ymc9@users.noreply.github.com>
Fields inherited via a mixin type on a delegate base model were not
getting their `originModel` set in the generated schema, causing the
ORM to include them in the wrong table's INSERT statement.
Introduces `getOwnedFields` and `getDelegateOriginModel` helpers in
`model-utils.ts` and uses them in both `ts-schema-generator` and
`prisma-schema-generator`, replacing the previous logic that only
checked `field.$container` directly.
Fixes#2351
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fixed issue where access policy rules couldn't reference fields inherited from mixins defined in separate imported files. The language service now correctly resolves these fields during scope computation.
## Root Cause
The `getRecursiveBases()` function only searched for mixin declarations in the current document (`decl.$container.declarations`), which failed for imported mixins.
## Solution
- Modified `getRecursiveBases()` to accept optional `LangiumDocuments` parameter
- Implemented two-strategy approach:
1. Use resolved reference if available (post-linking)
2. Search by name across all documents including imports (pre-linking)
- Updated `ZModelScopeComputation.processNode()` to pass `LangiumDocuments`
- Leverages existing `getAllDeclarationsIncludingImports()` helper
## Changes
- **packages/language/src/utils.ts**: Fixed `getRecursiveBases()` to search imported documents
- **packages/language/src/zmodel-scope.ts**: Pass LangiumDocuments to scope computation
- **packages/language/test/mixin.test.ts**: Added tests for imported mixin field resolution
- **packages/testtools**: Added `extraZModelFiles` option for multi-file test schemas
- **tests/regression/test/issue-598.test.ts**: Regression test for the issue
## Test Results
✅ All language package tests pass (65 tests)
✅ Regression test validates policy rules can access imported mixin fields
✅ Handles edge cases: cyclic imports, nested mixins, transitive imports
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
* WIP(orm): mysql support
* WIP: more progress with fixing tests
* WIP: get all client api tests pass
* WIP: get all tests pass
* fix executor
* add MySQL to CI matrix
* fix sqlite test runs
* fix test
* fix delete readback check
* set mysql container max connections
* fix tests
* fix test
* refactor: extract duplicated mysql/pg code into base class
* address PR comments
* refactor: remove order by duplicated code
* refactor: optimize stripTableReference
* addressing PR comments
* fix tests