Skip to content

Latest commit

 

History

History
77 lines (60 loc) · 3.12 KB

PX1034.md

File metadata and controls

77 lines (60 loc) · 3.12 KB

PX1034

This document describes the PX1034 diagnostic.

Summary

Code Short Description Type Code Fix
PX1034 The DAC does not have an explicit foreign key declaration Warning (ISV Level 3: Informational) Available

Diagnostic Description

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 an attribute derived from the PXCacheName attribute, or an attribute derived from the PXPrimaryGraphBase attribute such as PXPrimaryGraphAttribute. 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

Example of Code for Which the Warning Is Shown

[PXCacheName(Messages.SOOrder)]
public class SOOrder : PXBqlTable, IBqlTable
{
	// DAC field declarations

	#region Keys
	// no FK
	
	#endregion
	
	...
}

Example of the Code Fix

[PXCacheName(Messages.SOOrder)]
public class SOOrder : PXBqlTable, 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
	
	...
}

Related Articles

Foreign Keys and Nullable Columns
To Define a Foreign Key
PXCacheNameAttribute Class
PXPrimaryGraphAttribute Class