Defining and using one-to-one associations
Note, this type of relation is not yet fully handled but it is planned and will come shortly.
Available methods
- Method set{AssocRecordType}
Associated record may be an object (instance of PorteRecord), an int (or a string which cast to an int), an array (representing the record, eg issued from the "toArray" method) or null (if property not tagged as not_null),
- param PorteRecord || int || string || array || null: The associated record or its primary key value or its array representation
- return PorteRecord: The current record
- Method get{AssocRecordType}
Setting up the "belongs_to" property
The following keys may be used:
- Key "field": Define the database field storing the primary key of the associated record, default to the property name.
- Key "belongs_to": An array defining various internal properties. Also, it may be a value, or its value
may be a boolean, as string or an array. If the value is a string, it correspond to the "type" of the
associated record.
- Key "type": Define the type of the associated record
- Key "class": Define the class of the associated record, used as an alternative to define the "type" of records if not set
- Key "property": Define the name of the property defining the "belongs_to" association, default to current plural record type.
Once a property is clean up by its model, the resulting config is:
- Key "belongs_to": always an array
- Key "type"
- Key "property"
- Key "field"
- Key "type"
- Key "foreign_key": Boolean value set to true
Setting up the "has_one" property
The following keys may be used:
- Key "has_one": An array defining various internal properties. It may also be a value, or its value
may be a boolean, as string or an array. If the value is a string, it corresponds to the "type" of the
associated record.
- Key "type": Define the type of the associated records
- Key "class": Define the class of the associated record, used as an alternative to define the "type" of records if not set
- Key "property": Define the name of the property defining the "belongs_to" association, default to current record type.
Once a property is clean up by its model, the resulting config is:
- Key "has_one": always an array
- Key "type"
- Key "property"
- Key "transient": Mark the property as not persisted in the database