This document describes the PX1034 diagnostic.
Code | Short Description | Type | Code Fix |
---|---|---|---|
PX1034 | The DAC does not have an explicit foreign key declaration | Warning (ISV Level 3: Informational) | Available |
You can define foreign keys in a DAC. The diagnostic suggests adding a foreign key definition to a DAC. The warning is shown only for DACs that have the PXCacheName
or PXPrimaryGraph
attribute.
The diagnostic does not check abstract DACs and DACs which have only unbound DAC properties (fully-unbound DACs used for custom popups and filters for inquiry forms).
To fix the issue, add the public static FK class to the DAC.
The code fix adds public static FK class. Inside the class, there is a big comment with examples of different foreign keys and a list of DAC properties which have a high probability of holding foreign key. The probability is determined by the analysis of attributes declared on DAC property. Acuminator looks for the following attribute or attributes derived from the attributes:
- PXParent
- PXDBDefault
- PXSelector
- PXDimensionSelector
- PXForeignReference
[PXCacheName(Messages.SOOrder)]
public class SOOrder : IBqlTable
{
// DAC field declarations
#region Keys
// no FK
#endregion
...
}
[PXCacheName(Messages.SOOrder)]
public class SOOrder : IBqlTable
{
// DAC field declarations
#region Keys
public static class FK
{
// Add all foreign keys for the DAC here. For referenced DACs with a PK class, you can use the following template:
// public class ReferencedDacFK : ReferencedDAC.PK.ForeignKeyOf<SOOrder>.By<joinField1, joinFields, ...> { }
//
// For referenced DACs without a PK class and with a single primary key field, you can use the following template:
// public class ReferencedDacFK : Field<joinField>.IsRelatedTo<ReferencedDAC.keyField>.AsSimpleKey.WithTablesOf<ReferencedDAC, SOOrder> { }
//
// For referenced DACs without a PK class and with a composite primary key, you can use the following template:
/* public class ReferencedDacFK : CompositeKey<
Field<joinField1>.IsRelatedTo<ReferencedDAC.keyField1>,
Field<joinField2>.IsRelatedTo<ReferencedDAC.keyField2>,
...
>.WithTablesOf<SOOrder, SOOrder> { } */
}
#endregion
...
}
Foreign Keys and Nullable Columns
To Define a Foreign Key
PXCacheNameAttribute Class
PXPrimaryGraphAttribute Class