Tech Tip: Utility Method To See if a Field is a Related Many
PRODUCT: 4D | VERSION: 15 | PLATFORM: Mac & Win
Published On: August 21, 2015
Below is a utility method that will return a boolean output based on whether the passed pointer to a field is a related many or not.
// Method: IsRelatedMany // Parameters: // $1 - Pointer the the Field // Output: // $0 = True: Is a Related Many // $0 = False: Is NOT a Related Many // //----------------------------------------------------------------------- C_POINTER($1;$field_p) C_BOOLEAN($0;$result_b) C_LONGINT($tableID_l;$fieldID_l) ARRAY LONGINT($tableID_al;0) ARRAY LONGINT($fieldID_al;0) If (Count parameters=1) $result_b:=False $field_p:=$1 $fieldID_l:=Field($field_p) $tableID_l:=Table($field_p) Begin SQL SELECT UCC.COLUMN_ID FROM _USER_CONS_COLUMNS AS UCC, _USER_CONSTRAINTS AS UC WHERE UC.CONSTRAINT_TYPE = '4DR' AND UCC.CONSTRAINT_ID=UC.CONSTRAINT_ID AND UC.TABLE_ID=:$tableID_l AND UCC.COLUMN_ID=:$fieldID_l INTO :$fieldID_al; End SQL If (Size of array($fieldID_al)>0) $result_b:=True End if $0:=$result_b End if |
Example of using the method on the following Tables:
C_BOOLEAN($res1;$res2;$res3) $res1:=IsRelatedMany (->[SampleOne]ID) $res2:=IsRelatedMany (->[SampleManyA]ID) $res3:=IsRelatedMany (->[SampleManyA]Field_2) TRACE |
Results in:
$res1:=False $res2:=True $res3:=False |