mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
* entc/gen: add OwnFK indicator for type edges * entc/gen: add Edges field for generated types * entc/gen: add With<T> method to query-builder template * entc/gen: scan and assign foreign-keys on eager-loading * entc/gen: load fk-relations (wip) * entc/integration: add o2m/m2o tests for eager-loading * entc/gen: add m2m support for eager-loading * entc/gen: add integration tests for m2m and subgraphs * entc/gen/integration: add tests for o2o eager-loading * all: generate all assets
57 lines
2.0 KiB
Cheetah
57 lines
2.0 KiB
Cheetah
{{/*
|
|
Copyright 2019-present Facebook Inc. All rights reserved.
|
|
This source code is licensed under the Apache 2.0 license found
|
|
in the LICENSE file in the root directory of this source tree.
|
|
*/}}
|
|
|
|
{{/* constants needed for sql dialects. */}}
|
|
{{ define "dialect/sql/meta/constants" }}
|
|
// Table holds the table name of the {{ lower $.Name }} in the database.
|
|
Table = "{{ $.Table }}"
|
|
{{- range $_, $e := $.Edges }}
|
|
// {{ $e.TableConstant }} is the table the holds the {{ $e.Name }} relation/edge.
|
|
{{- if $e.M2M }} The primary key declared below.{{ end }}
|
|
{{ $e.TableConstant }} = "{{ $e.Rel.Table }}"
|
|
{{- if ne $.Table $e.Type.Table }}
|
|
// {{ $e.InverseTableConstant }} is the table name for the {{ $e.Type.Name }} entity.
|
|
// It exists in this package in order to avoid circular dependency with the "{{ $e.Type.Package }}" package.
|
|
{{ $e.InverseTableConstant }} = "{{ $e.Type.Table }}"
|
|
{{- end }}
|
|
{{- if not $e.M2M }}
|
|
// {{ $e.ColumnConstant }} is the table column denoting the {{ $e.Name }} relation/edge.
|
|
{{ $e.ColumnConstant }} = "{{ $e.Rel.Column }}"
|
|
{{- end }}
|
|
{{- end }}
|
|
{{ end }}
|
|
|
|
{{/* variables needed for sql dialects. */}}
|
|
{{ define "dialect/sql/meta/variables" }}
|
|
// Columns holds all SQL columns for {{ lower $.Name }} fields.
|
|
var Columns = []string{
|
|
{{ $.ID.Constant }},
|
|
{{- range $f := $.Fields }}
|
|
{{ $f.Constant }},
|
|
{{- end }}
|
|
}
|
|
{{/* if any of the edges owns a foreign-key */}}
|
|
{{ with $.ForeignKeys }}
|
|
// ForeignKeys holds the SQL foreign-keys that are owned by the {{ $.Name }} type.
|
|
var ForeignKeys = []string{
|
|
{{- range $fk := . }}
|
|
"{{ $fk.Field.Name }}",
|
|
{{- end }}
|
|
}
|
|
{{ end }}
|
|
|
|
{{ with $.NumM2M }}
|
|
var (
|
|
{{- range $_, $e := $.Edges }}
|
|
{{- if $e.M2M }}
|
|
// {{ $e.PKConstant }} and {{ $e.ColumnConstant }}2 are the table columns denoting the
|
|
// primary key for the {{ $e.Name }} relation (M2M).
|
|
{{ $e.PKConstant }} = []string{"{{ index $e.Rel.Columns 0 }}", "{{ index $e.Rel.Columns 1 }}"}
|
|
{{- end }}
|
|
{{- end }}
|
|
)
|
|
{{ end }}
|
|
{{ end }} |