Skip to content

RelationshipOneToOne

Carlo Barazzetta edited this page Jan 27, 2017 · 2 revisions

How to define a "Has One" reference between models

Please refer to here for general information about models.

If you want to define a "Has One" reference between models you have to use a Reference type field.

Example of Reference in HelloKitto

# model Hair.yaml
ModelName: Hair
...
Fields:
  Hair_Id: String(32) not null primary key
    IsVisible: False
    DefaultValue: %COMPACT_GUID%
.....
# model Girl.yaml
ModelName: Girl
Fields:
  Hair: Reference(Hair)
    PhysicalName: FK_GIRL_HAIR
    Fields:
      HairId:
        PhysicalName: HAIR_ID
...

Note that:

  • Hair is the logical field name.
  • The subnode PhysicalName (in this case FK_GIRL_HAIR) is the name of the constraint that Kitto will use as Alias to build joins in Sql command text.
  • The subnode Fields contains the field HairId that make up the key to the model Hair.

The subnode Fields must contain all fields that makes up the key to the other model. These fields only need names, as their data types and other properties are taken from the corresponding fields in the referenced model primary key.

A reference field is rendered in user interface as a combo box: RelationshipOneToOne.png

Kitto shows in the combo the CaptionField for the referenced model. In this case Kitto is using the default value, the first visible not-key field for the model (Hair_Color).

In case of reference to a model with the option IsLarge: True set, the combo box will use paging, as in the following example from Taskitto:

# model Employee.yaml
ModelName: EMPLOYEE
IsLarge: True
Fields:
  EMPLOYEE_ID: String(32) not null primary key
    IsVisible: False
    DefaultValue: %COMPACT_GUID%
# model Activity.yaml
ModelName: ACTIVITY
Fields:
....
  EMPLOYEE: Reference(EMPLOYEE) not null
    Fields:
      EMPLOYEE_ID:
        PhysicalName: EMPLOYEE_ID
....

ComboIsLarge.png

If you prefer, you can tell Kitto to open an existing view instead of rendering a combo. Just set IsLookup: True in the view:

# view Employees.yaml 
Type: Data
IsLookup: True

ReferenceIsLarge.png

Here is a more complex case with multiple keys from KEmployee:

# model Job.yaml 
ModelName: Job
Fields:
  JobCode: String(5) not null primary key
    PhysicalName: JOB_CODE
  JobGrade: Integer not null primary key
....
  JobCountryRef: Reference(Country) not null primary key
    PhysicalName: JOB_COUNTRY
    Fields:
      JobCountry:
        PhysicalName: JOB_COUNTRY
# model Employee.yaml
ModelName: Employee
IsLarge: True
PhysicalName: EMPLOYEE
Fields:
  EmpNo: Integer not null primary key
    PhysicalName: EMP_NO
....
  JobRef: Reference(Job) not null
    Fields:
      JobCode:
        PhysicalName: JOB_CODE
      JobGrade:
        PhysicalName: JOB_GRADE
      JobCountry:
        PhysicalName: JOB_COUNTRY
# view Employees.yaml
Type: Data
IsLookup: True
Clone this wiki locally