Skip to content

Commit

Permalink
entc/gen: skip Table() predicate and warn about reserved schema nam…
Browse files Browse the repository at this point in the history
…e (`Client`) (#2486)

* entc/gen: do no generate `Table()` predicate and warn the user in case of reserved schema name like `Client`.

* doc/md: document reserved schema name

* doc/md: revert reserved schema name as this was already working

* doc/md: rephrase
  • Loading branch information
masseelch committed Apr 20, 2022
1 parent 4e1affe commit 2c8e58c
Show file tree
Hide file tree
Showing 17 changed files with 630 additions and 3 deletions.
6 changes: 6 additions & 0 deletions doc/md/schema-def.md
Expand Up @@ -58,6 +58,12 @@ the root directory of your project, and can be generated by `entc` as follows:
go run entgo.io/ent/cmd/ent init User Group
```

:::note
Please note, that some schema names (like `Client`) are not available due to
[internal use](https://pkg.go.dev/entgo.io/ent/entc/gen#ValidSchemaName). You can circumvent reserved names by using an
annotation as mentioned [here](schema-annotations.md#custom-table-name).
:::

## It's Just Another ORM

If you are used to the definition of relations over edges, that's fine.
Expand Down
2 changes: 1 addition & 1 deletion entc/gen/template/where.tmpl
Expand Up @@ -41,7 +41,7 @@ func ID(id {{ $.ID.Type }}) predicate.{{ $.Name }} {
{{/* JSON cannot be compared using "=" and Enum has a type defined with the field name */}}
{{ $hasP := not (or $f.IsJSON $f.IsEnum) }}
{{ $comparable := or $f.ConvertedToBasic $f.Type.Valuer }}
{{ $undeclared := (and (ne $func "Label") (ne $func "Hooks") (ne $func "Policy")) }}
{{ $undeclared := (and (ne $func "Label") (ne $func "Hooks") (ne $func "Policy") (ne $func "Table")) }}
{{- if and $hasP $comparable $undeclared }}
{{ $arg := "v" }}
// {{ $func }} applies equality check predicate on the {{ quote $f.Name }} field. It's identical to {{ $func }}EQ.
Expand Down
12 changes: 12 additions & 0 deletions entc/integration/ent/comment.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions entc/integration/ent/comment/comment.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions entc/integration/ent/comment/where.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions entc/integration/ent/comment_create.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2c8e58c

Please sign in to comment.