Skip to content

Commit

Permalink
merge from dev (#1132)
Browse files Browse the repository at this point in the history
Co-authored-by: ErikMCM <[email protected]>
Co-authored-by: Jason Kleinberg <[email protected]>
Co-authored-by: Jonathan S <[email protected]>
Co-authored-by: Jiasheng <[email protected]>
  • Loading branch information
5 people authored Mar 13, 2024
1 parent a662107 commit ea4442b
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 10 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<a href="https://twitter.com/zenstackhq">
<img src="https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fzenstackhq%2Fzenstack">
</a>
<a href="https://go.zenstack.dev/chat">
<a href="https://discord.gg/Ykhr738dUe">
<img src="https://img.shields.io/discord/1035538056146595961">
</a>
<a href="https://github.com/zenstackhq/zenstack/blob/main/LICENSE">
Expand Down Expand Up @@ -142,7 +142,7 @@ The following diagram gives a high-level architecture overview of ZenStack.

- [Home](https://zenstack.dev)
- [Documentation](https://zenstack.dev/docs)
- [Community chat](https://go.zenstack.dev/chat)
- [Community chat](https://discord.gg/Ykhr738dUe)
- [Twitter](https://twitter.com/zenstackhq)
- [Blog](https://zenstack.dev/blog)

Expand All @@ -162,7 +162,7 @@ The following diagram gives a high-level architecture overview of ZenStack.
- [SWR](https://github.com/vercel/swr) and [TanStack Query](https://github.com/TanStack/query) hooks generator
- OpenAPI specification generator
- [tRPC](https://trpc.io) router generator
- 🙋🏻 [Request for a plugin](https://go.zenstack.dev/chat)
- 🙋🏻 [Request for a plugin](https://discord.gg/Ykhr738dUe)

### Framework adapters

Expand All @@ -171,15 +171,15 @@ The following diagram gives a high-level architecture overview of ZenStack.
- [SvelteKit](https://zenstack.dev/docs/reference/server-adapters/sveltekit)
- [Fastify](https://zenstack.dev/docs/reference/server-adapters/fastify)
- [ExpressJS](https://zenstack.dev/docs/reference/server-adapters/express)
- 🙋🏻 [Request for an adapter](https://go.zenstack.dev/chat)
- 🙋🏻 [Request for an adapter](https://discord.gg/Ykhr738dUe)

### Prisma schema extensions

- [Custom attributes and functions](https://zenstack.dev/docs/reference/zmodel-language#custom-attributes-and-functions)
- [Multi-file schema and model inheritance](https://zenstack.dev/docs/guides/multiple-schema)
- Strong-typed JSON field (coming soon)
- Polymorphism (future)
- 🙋🏻 [Request for an extension](https://go.zenstack.dev/chat)
- 🙋🏻 [Request for an extension](https://discord.gg/Ykhr738dUe)

## Examples

Expand Down
4 changes: 2 additions & 2 deletions packages/schema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ This VS Code extension provides code editing helpers for authoring ZenStack's sc

- [Home](https://zenstack.dev)
- [Documentation](https://zenstack.dev/docs)
- [Community chat](https://go.zenstack.dev/chat)
- [Community chat](https://discord.gg/Ykhr738dUe)
- [Twitter](https://twitter.com/zenstackhq)
- [Blog](https://dev.to/zenstack)

## Community

Join our [discord server](https://go.zenstack.dev/chat) for chat and updates!
Join our [discord server](https://discord.gg/Ykhr738dUe) for chat and updates!

## License

Expand Down
9 changes: 6 additions & 3 deletions packages/sdk/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,14 @@ export function isIdField(field: DataModelField) {
return true;
}

// NOTE: we have to use name to match fields because the fields
// may be inherited from an abstract base and have cloned identities

const model = field.$container as DataModel;

// model-level @@id attribute with a list of fields
const modelLevelIds = getModelIdFields(model);
if (modelLevelIds.includes(field)) {
if (modelLevelIds.map((f) => f.name).includes(field.name)) {
return true;
}

Expand All @@ -235,12 +238,12 @@ export function isIdField(field: DataModelField) {
// then, the first field with @unique can be used as id
const firstUniqueField = model.fields.find((f) => hasAttribute(f, '@unique'));
if (firstUniqueField) {
return firstUniqueField === field;
return firstUniqueField.name === field.name;
}

// last, the first model level @@unique can be used as id
const modelLevelUnique = getModelUniqueFields(model);
if (modelLevelUnique.includes(field)) {
if (modelLevelUnique.map((f) => f.name).includes(field.name)) {
return true;
}

Expand Down
87 changes: 87 additions & 0 deletions tests/integration/tests/regression/issue-1129.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { createPostgresDb, dropPostgresDb, loadSchema } from '@zenstackhq/testtools';

describe('Regression for issue 1129', () => {
it('regression', async () => {
let prisma;
const dbUrl = await createPostgresDb('regression-issue-1129');

try {
const r = await loadSchema(
`
model Relation1 {
id String @id @default(cuid())
field1 String
concrete Concrete[]
@@allow('all', true)
}
model Relation2 {
id String @id @default(cuid())
field2 String
concrete Concrete[]
@@allow('all', true)
}
abstract model WithRelation1 {
relation1Id String
relation1 Relation1 @relation(fields: [relation1Id], references: [id])
}
abstract model WithRelation2 {
relation2Id String
relation2 Relation2 @relation(fields: [relation2Id], references: [id])
}
model Concrete extends WithRelation1, WithRelation2 {
concreteField String
@@id([relation1Id, relation2Id])
@@allow('all', true)
}
`,
{ provider: 'postgresql', dbUrl }
);

prisma = r.prisma;
const db = r.enhance();

await db.$transaction(async (tx: any) => {
await tx.relation2.createMany({
data: [
{
id: 'relation2Id1',
field2: 'field2Value1',
},
{
id: 'relation2Id2',
field2: 'field2Value2',
},
],
});

await tx.relation1.create({
data: {
field1: 'field1Value',
concrete: {
createMany: {
data: [
{
concreteField: 'concreteFieldValue1',
relation2Id: 'relation2Id1',
},
{
concreteField: 'concreteFieldValue2',
relation2Id: 'relation2Id2',
},
],
},
},
},
});
});
} finally {
if (prisma) {
await prisma.$disconnect();
}
await dropPostgresDb('regression-issue-1129');
}
});
});

0 comments on commit ea4442b

Please sign in to comment.