Skip to content

RelationshipOneToOne

iraichi edited this page Apr 24, 2015 · 24 revisions

How to define a "Has One" reference between models

Please refer to here for general informations 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.yalm
ModelName: Hair
...
Fields:
  Hair_Id: String(32) not null primary key
    IsVisible: False
    DefaultValue: %COMPACT_GUID%
.....
# model Girl.yalm
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 join 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's 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 field different from a key for the model (Hair_Color).

in case of reference to a model with the option IsLarge: True setted the combo box will page as in the following example from Taskitto:

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

ComboIsLarge.png

If you prefer you can ask kitto to open an existing view instead of render a combo. Just set IsLookup: True in theview:

# view Employees.yalm 
Type: Data
IsLookup: True

ReferenceIsLarge.png

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

# model Job.yalm 
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.yalm
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.yalm
Type: Data
IsLookup: True

Clone this wiki locally