# zg-entity

*<mark style="color:blue;">zg-entity or zg-e</mark>*

<figure><img src="/files/4mmABJK4BKVxbZbmyCAH" alt=""><figcaption></figcaption></figure>

*zg-entity is a predefined object to access to fields and properties of a table in the database. You need to write zg-entity with square brackets if you don't use it with a built-in function. In build-in functions it is used with parantheses.*

*zg-entity object can be used in zsif, zref and ziref file directly.*

### *<mark style="color:blue;">Example Usage</mark>*

```
// access to name field of an entity
[[[zg-entity...zg-name]]]
// or
[[[zg-e...zg-name]]]
```

### *<mark style="color:blue;">Example Usage as a Built-in Function Parameter</mark>*

```
// access to name field of an entity and singularize it using built-in function
zg-singularize(((zg-entity...zg-name)))
//or
zg-singularize(((zg-e...zg-name)))
```

### *<mark style="color:blue;">Fields and Properties of zg-entity</mark>*

*Every field and property has a purpose in Zontroy to store spesific data for code generation.*&#x20;

![](/files/IFOqHi6G0fLBCauVfRGQ)

#### *<mark style="color:blue;">zg-fields or zg-fs</mark>*

*zg-fields is a collection of fields in an entity like columns in a table. You need to iterate zg-fields using zg-for loop to access the properties of each field.*

```
[[[zg-entity...zg-fields]]]
//or
[[[zg-entity...zg-fs]]]
// example usage
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-name]]] }}}
```

*<mark style="color:blue;">**zg-field or zg-f**</mark>*

*zg-field or zg-f is* each one *from a collection of fields in an entity like columns in a table.*

```
//usage
[[[zg-entity...zg-field]]]
// or 
[[[zg-entity...zg-f]]]
```

*<mark style="color:blue;">**zg-pkField" or zg-pk**</mark>*

*Returns the field, which is the primary key of any entity in the database.*

```
// usage
[[[zg-entity...zg-pkField...zg-name]]]
// or 
[[[zg-entity...zg-pk...zg-name]]]
```

#### *<mark style="color:blue;">zg-pkFields or zg-pks</mark>*

*This is a collection of primary key fields in a table. This property supports multiple primary keys. While iterating list of primary keys you can access the properties of each primary key field.*

```
[[[zg-entity...zg-pkFields]]]
//or
[[[zg-entity...zg-pks]]]
```

*<mark style="color:blue;">**zg-nonPKFields or zg-npks**</mark>*

It is responsible for fetching fields from within the entity that do not have primary keys.

```
//usage
[[[zg-entity...zg-nonPKFields]]]
//or
[[[zg-entity...zg-npks]]]
// for example
zg-for(((zg-item:::[[[zg-entity...zg-nonPKFields]]]))){{{
[[[zg-item...zg-name]]]
}}}
```

*<mark style="color:blue;">**zg-nonKeyFields or zg-nkfs**</mark>*

It is responsible for fetching fields that do not have primary keys and foreign keys from within the entity.

```
//usage
zg-for(((zg-item:::[[[zg-entity...zg-nonKeyFields]]]))){{{
[[[zg-item...zg-name]]]
}}}
// or
zg-for(((zg-item:::[[[zg-entity...zg-nkfs]]]))){{{
[[[zg-item...zg-name]]]
}}}
```

*<mark style="color:blue;">**zg-fkFields or zg-fks**</mark>*

Returns fields with foreign keys in the entity.

```
//usage
zg-for(((zg-item:::[[[zg-entity...zg-fkFields]]]))){{{
[[[zg-item...zg-name]]]
}}}
// or
zg-for(((zg-item:::[[[zg-entity...zg-fks]]]))){{{
[[[zg-item...zg-name]]]
}}}
```

*<mark style="color:blue;">**zg-nonFKFields or zg-nfks**</mark>*

Returns fields in the entity that do not contain foreign keys.

```
//usage
zg-for(((zg-item:::[[[zg-entity...zg-nonFKFields]]]))){{{
[[[zg-item...zg-name]]]
}}}
// or
zg-for(((zg-item:::[[[zg-entity...zg-nfks]]]))){{{
[[[zg-item...zg-name]]]
}}}
```

#### *<mark style="color:blue;">zg-referencingFields or zg-ref</mark>*

*List of referencing fields of an entity is accesible by zg-referencingFields. It also means that zg-referencingFields is a collection of foreign keys in a table.*

```
[[[zg-entity...zg-referencingFields]]]
//or
[[[zg-entity...zg-ref]]]
```

#### *<mark style="color:blue;">zg-referencedFields or zg-refs</mark>*&#x20;

*zg-referencingFields is an object for the list of referenced fields of an entity by another entity. It also means that zg-referencedFields is a collection of columns in a table referenced by another table in the database.*

```
[[[zg-entity...zg-referencedFields]]]
//or
[[[zg-entity...zg-refs]]]
```

*<mark style="color:blue;">**zg-dataType or zg-dt**</mark>*

*Returns the data type of any field in the entity.*

<pre><code><strong>//usage
</strong><strong>zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
</strong><strong>[[[zg-item...zg-dataType]]] }}}
</strong><strong>// or
</strong>zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-dt]]] }}}
</code></pre>

*<mark style="color:blue;">**zg-targetType or zg-tt**</mark>*

*It refers to the equivalent of the datatype of a field in an entity in the database in any programming language.*

```
//usage
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-targetType]]] }}}
// for mysql and go 
// datatype of zg-item is bigint, targettype of zg-item is bigint->int64 | so it is int64
// or
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-tt]]] }}}
```

*<mark style="color:blue;">**zg-nullTargetType or zg-ntt**</mark>*

Returns the null target type value in any programming language of the data type of a field in an entity in the database.

```
//usage
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-nullTargetType]]] }}}
// or
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-ntt]]] }}}
```

*<mark style="color:blue;">**zg-primitiveType or zg-pt**</mark>*

Returns the primitive type value in any programming language of the data type of a field in an entity in the database.

```
//usage
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-primitiveType]]] }}}
// or
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-pt]]] }}}
```

*<mark style="color:blue;">**zg-default or zg-def**</mark>*

*Returns the default value of any field in the entity*

```
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-default]]] }}}
// or 
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-def]]] }}}
```

*<mark style="color:blue;">**zg-required or zg-r**</mark>*

It is used to express that the value of the field in the entity cannot be empty.

```
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-required]]] }}}
// or 
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-r]]] }}}
```

*<mark style="color:blue;">**zg-maxLength or zg-ml**</mark>*

It is used to get the maximum length of the value of the field in the entity.

```
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-maxLength]]] }}}
// or 
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-ml]]] }}}
```

*<mark style="color:blue;">**zg-NumericPrecision or zg-np**</mark>*

Precision is the number of digits in a number and finds the precision of the number of digits before the decimal point.

```
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-NumericPrecision]]] }}}
// or 
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-np]]] }}}
```

*<mark style="color:blue;">**zg-NumericScale or zg-ns**</mark>*

Scale is the number of digits to the right of the decimal point in a number and deals with the precision of the number of digits after the decimal point.

```
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-NumericScale]]] }}}
// or 
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-ns]]] }}}
```

*<mark style="color:blue;">**zg-DatetimePrecision or zg-dp**</mark>*

Indicates how precisely date and time data is recorded. This means that data containing date and time information can be stored in detail down to subunits such as seconds, milliseconds, microseconds.

```
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-DatetimePrecision]]] }}}
// or 
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-dp]]] }}}
```

*<mark style="color:blue;">**zg-referencedEntity or  zg-re**</mark>*

"zg-referencedEntity" is a term that usually refers to another entity in a system or data model. In relational databases, this refers to the connection of a particular entity to another entity. So Returns the entity that is a reference to the entity.

```
[[[zg-entity...zg-referencedEntity]]]
// or 
[[[zg-entity...zg-re]]]
```

*<mark style="color:blue;">**zg-referencedEntityName or zg-ren**</mark>*

Returns the entity name that is a reference to the entity.

```
[[[zg-entity...zg-referencedEntityName]]]
// or 
[[[zg-entity...zg-ren]]]
```

*<mark style="color:blue;">**zg-referencedFieldName or zg-rfn**</mark>*

Returns the field name that is a reference to the field in entity.

```
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-referencedFieldName]]] }}}
// or 
zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
[[[zg-item...zg-rfn]]] }}}
```

*<mark style="color:blue;">**zg-generateBlock**</mark>*

Generate block If we only want code generation in one block of the code file, we add generate block to that section.

```
zg-generateBlock((([[[zg-entity...zg-pkField...zg-name]]])))
```

*<mark style="color:blue;">**zg-protectBlock**</mark>*

Protect block ensures that the code is not crushed during code generation if we want a part of the existing code to be protected and not changed.

```
zg-protectBlock((([[[zg-entity...zg-pkField...zg-name]]])))
```

#### *<mark style="color:blue;">zg-schema</mark>*

*It means the name of schema in the database.*

```
[[[zg-entity...zg-schema]]]
```

#### *<mark style="color:blue;">zg-name or zg-n</mark>*

*It means the name of entity in the database.*

```
[[[zg-entity...zg-name]]]
//or
[[[zg-entity...zg-n]]]
```

#### *<mark style="color:blue;">zg-targetName or zg-tn</mark>*

*It means the name of entity given by developer in Zontroy Properties Window.*

```
[[[zg-entity...zg-targetName]]]
//or
[[[zg-entity...zg-tn]]]
```

#### *<mark style="color:blue;">zg-alternativeName or zg-an</mark>*

*It means the alternative name of entity given by developer in Zontroy Properties Window.*

```
[[[zg-entity...zg-alternativeName]]]
//or
[[[zg-entity...zg-an]]]
```

#### *<mark style="color:blue;">zg-label</mark>*

*It means the label of entity given by developer in Zontroy Properties Window.*

```
[[[zg-entity...zg-label]]]
```

#### *<mark style="color:blue;">zg-rowOrder or zg-ro</mark>*

*It means the order of entity given by developer in Zontroy Properties Window. Zontroy sorts entities by value of row order property automatically.*

```
[[[zg-entity...zg-rowOrder]]]
//or
[[[zg-entity...zg-ro]]]
```

#### *<mark style="color:blue;">zg-description or zg-d</mark>*

*It means the description of entity given by developer in Zontroy Properties Window.*

```
[[[zg-entity...zg-description]]]
//or
[[[zg-entity...zg-d]]]
```

#### *<mark style="color:blue;">zg-displayFields or zg-dfs</mark>*

*zg-displayFields is a collection of fields enterd by developer in Zontroy Properties Window and it is a group of field to use further.*

```
[[[zg-entity...zg-displayFields]]]
//or
[[[zg-entity...zg-dfs]]]
```

#### <mark style="color:blue;">zg-extra1 or zg-e1</mark>

*zg-extra1 is a reserved property to be given by developer for personal purpose in Zontroy Properties Window.*

```
[[[zg-entity...zg-extra1]]]
//or
[[[zg-entity...zg-e1]]]
```

#### *<mark style="color:blue;">zg-extra2 or zg-e2</mark>*

*zg-extra2 is a reserved property to be given by developer for personal purpose in Zontroy Properties Window.*

```
[[[zg-entity...zg-extra2]]]
//or
[[[zg-entity...zg-e2]]]
```

#### *<mark style="color:blue;">zg-extra3 or zg-e3</mark>*

*zg-extra3 is a reserved property to be given by developer for personal purpose in Zontroy Properties Window.*

```
[[[zg-entity...zg-extra3]]]
//or
[[[zg-entity...zg-e3]]]
```

#### *<mark style="color:blue;">zg-extra4 or zg-e4</mark>*

*zg-extra4 is a reserved property to be given by developer for personal purpose in Zontroy Properties Window.*

```
[[[zg-entity...zg-extra4]]]
//or
[[[zg-entity...zg-e4]]]
```

#### <mark style="color:blue;">zg-extra5 or zg-e5</mark>

z*g-extra5 is a reserved property to be given by developer for personal purpose in Zontroy Properties Window.*

```
[[[zg-entity...zg-extra5]]]
//or
[[[zg-entity...zg-e5]]]
```

#### *<mark style="color:blue;">zg-extra6 or zg-e6</mark>*

*zg-extra6 is a reserved property to be given by developer for personal purpose in Zontroy Properties Window.*

```
[[[zg-entity...zg-extra6]]]
//or
[[[zg-entity...zg-e6]]]
```

#### *<mark style="color:blue;">zg-extra7 or zg-e7</mark>*

*zg-extra7 is a reserved property to be given by developer for personal purpose in Zontroy Properties Window.*

```
[[[zg-entity...zg-extra7]]]
//or
[[[zg-entity...zg-e7]]]
```

#### *<mark style="color:blue;">zg-extra8 or zg-e8</mark>*

*zg-extra8 is a reserved property to be given by developer for personal purpose in Zontroy Properties Window.*

```
[[[zg-entity...zg-extra8]]]
//or
[[[zg-entity...zg-e8]]]
```

#### *<mark style="color:blue;">zg-extra9 or zg-e9</mark>*

*zg-extra9 is a reserved property to be given by developer for personal purpose in Zontroy Properties Window.*

```
[[[zg-entity...zg-extra9]]]
//or
[[[zg-entity...zg-e9]]]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zontroy.com/zontroy-offline-code-generator/zontroy-ai-offline-code-generator-tutorial/zg-entity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
