Relationships and primary keys in MVC
Distinguishes model identity from submodel relationships.
Overview
SetPrimaryKey defines the first FormField identity, not one key per grid. The framework can use an SX2-declared key. SetRelation defines detail loading/foreign-key linkage to its owner, including detail order. Use the child table xFilial because parent/child sharing can differ. This uninvoked configuration uses hypothetical ZZ1/ZZ2 fields and indexes that must exist in the dictionary. Configure before Activate and test insert, update, copy and delete. (Sources: refs. 1–2.)
Commented example
#Include "Protheus.ch"
User Function Ed615()
// ZZ1/ZZ2 model already defined but not active; blocks not invoked.
Local bKey := {|oModel| oModel:SetPrimaryKey({"ZZ1_FILIAL","ZZ1_COD"})}
Local bRelation := {|oModel| oModel:SetRelation("ZZ2DETAIL", ;
{{"ZZ2_FILIAL",'xFilial("ZZ2")'}, {"ZZ2_COD","ZZ1_COD"}}, ;
"ZZ2_FILIAL+ZZ2_COD+ZZ2_ITEM")}
ConOut(ValType(bKey)+ValType(bRelation))
Return NilCreates two blocks, BB; neither creates tables nor configures a real model. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Verify IDs, expressions, types, duplicates and integrity. The parent key is not the complete detail order.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.