generating set pk method for struct with diff_removed token

This commit is contained in:
Pavel Merzlyakov 2024-01-19 01:09:14 +03:00
parent e40e3fe776
commit 49cc0bd8ae
1 changed files with 16 additions and 6 deletions

View File

@ -41,6 +41,10 @@ type {{ s.name }} struct {
{{ _self.data_root_methods(s) }}
{% endif %}
{% if has_token(s, 'diff_removed') %}
{{ _self.diff_removed_methods(s) }}
{% endif %}
{% if json_fields|length > 0 %}
type {{ json_fields_type }} struct{
{%~ for f in json_fields %}
@ -887,18 +891,24 @@ func (s *{{ name }}) FieldsMask() meta.FieldsMask {
{% set root_field = meta_field(token(s, 'data_root')) %}
{% set fields = s.fields|filter(f => not has_token(f, 'db_skip')) %}
{{ _self.root_set_pk(_context) }}
{{ _self.root_set_pk(s.name, fields, root_field) }}
{{ _self.root_save(_context) }}
{{ _self.root_load(_context) }}
{{ _self.root_delete(_context) }}
{% endmacro %}
{% macro root_set_pk(ctx) %}
{% set s = ctx.s %}
{% set set_field = ctx.root_field %}
func (s *{{ s.name }}) Set{{ set_field|fname }}({{ set_field|varname }} {{ set_field.type|go_type }}) {
{%~ for f in ctx.fields %}
{% macro diff_removed_methods(s) %}
{% set root_field = meta_field(token(s, 'data_root')) %}
{% set fields = s.fields|filter(f => not has_token(f, 'db_skip')) %}
{{ _self.root_set_pk(s.name, fields, root_field) }}
{% endmacro %}
{% macro root_set_pk(struct_name, fields, set_field) %}
func (s *{{ struct_name }}) Set{{ set_field|fname }}({{ set_field|varname }} {{ set_field.type|go_type }}) {
{%~ for f in fields %}
{%~ if f.type is array %}
{% set pkey = table_pkey(f.type.value) %}
{% set field_name = pkey|first|fname %}