================================================================================
TableRelation with preprocessor conditional at end
================================================================================

table 123 "Test Table"
{
    fields
    {
        field(1; "Type"; Option)
        {
            OptionMembers = " ","G/L Account",Item,"Allocation Account";
        }
        field(2; "No."; Code[20])
        {
            TableRelation = IF (Type = CONST("G/L Account")) "G/L Account"
            ELSE
            IF (Type = CONST(Item)) Item
            ELSE
            #if BC24
            IF (Type = CONST("Allocation Account")) "Allocation Account" WHERE("Account Type" = CONST(Fixed));
            #else
            IF (Type = CONST("Allocation Account")) "G/L Account";
            #endif;
        }
    }
}

--------------------------------------------------------------------------------

(source_file
  (table_declaration
    (table_keyword)
    object_id: (integer)
    object_name: (quoted_identifier)
    (fields_section
      (fields_keyword)
      (field_declaration
        id: (integer)
        name: (quoted_identifier)
        type: (type_specification
          (option_type))
        (property
          name: (property_name)
          value: (option_member_list
            (option_member
              (quoted_identifier))
            (option_member
              (quoted_identifier))
            (option_member
              (identifier))
            (option_member
              (quoted_identifier)))))
      (field_declaration
        id: (integer)
        name: (quoted_identifier)
        type: (type_specification
          (code_type
            length: (integer)))
        (property
          name: (property_name)
          value: (table_relation_value
            (table_relation_expression
              (if_table_relation
                (where_conditions
                  (where_condition
                    field: (identifier)
                    value: (quoted_identifier)))
                then_relation: (simple_table_relation
                  table: (quoted_identifier))
                else_relation: (table_relation_expression
                  (if_table_relation
                    (where_conditions
                      (where_condition
                        field: (identifier)
                        value: (identifier)))
                    then_relation: (simple_table_relation
                      table: (identifier))
                    else_relation: (table_relation_expression
                      (preproc_conditional_table_relation
                        (preproc_if
                          condition: (identifier))
                        (table_relation_expression
                          (if_table_relation
                            (where_conditions
                              (where_condition
                                field: (identifier)
                                value: (quoted_identifier)))
                            then_relation: (simple_table_relation
                              table: (quoted_identifier)
                              (where_clause
                                (where_conditions
                                  (where_condition
                                    field: (quoted_identifier)
                                    value: (identifier)))))))
                        (preproc_else)
                        (table_relation_expression
                          (if_table_relation
                            (where_conditions
                              (where_condition
                                field: (identifier)
                                value: (quoted_identifier)))
                            then_relation: (simple_table_relation
                              table: (quoted_identifier))))
                        (preproc_endif)))))))))))))

================================================================================
Simple TableRelation with preprocessor
================================================================================

table 124 "Simple Test"
{
    fields
    {
        field(1; "Field"; Code[20])
        {
            #if BC24
            TableRelation = "New Table";
            #else
            TableRelation = "Old Table";
            #endif
        }
    }
}

--------------------------------------------------------------------------------

(source_file
  (table_declaration
    (table_keyword)
    object_id: (integer)
    object_name: (quoted_identifier)
    (fields_section
      (fields_keyword)
      (field_declaration
        id: (integer)
        name: (quoted_identifier)
        type: (type_specification
          (code_type
            length: (integer)))
        (preproc_conditional
          (preproc_if
            condition: (identifier))
          (property
            name: (property_name)
            value: (quoted_identifier))
          (preproc_else)
          (property
            name: (property_name)
            value: (quoted_identifier))
          (preproc_endif))))))

================================================================================
TableRelation with multiple nested IFs and preprocessor
================================================================================

table 125 "Complex Test"
{
    fields
    {
        field(1; "Complex Field"; Code[20])
        {
            TableRelation = IF (Type = CONST(1)) Table1
            ELSE
            IF (Type = CONST(2)) Table2
            ELSE
            IF (Type = CONST(3)) Table3
            ELSE
            #if NEWVERSION
            Table4;
            #else
            Table5;
            #endif;

            trigger OnValidate()
            begin
                Message('Validated');
            end;
        }
    }
}

--------------------------------------------------------------------------------

(source_file
  (table_declaration
    (table_keyword)
    object_id: (integer)
    object_name: (quoted_identifier)
    (fields_section
      (fields_keyword)
      (field_declaration
        id: (integer)
        name: (quoted_identifier)
        type: (type_specification
          (code_type
            length: (integer)))
        (property
          name: (property_name)
          value: (table_relation_value
            (table_relation_expression
              (if_table_relation
                (where_conditions
                  (where_condition
                    field: (identifier)
                    value: (integer)))
                then_relation: (simple_table_relation
                  table: (identifier))
                else_relation: (table_relation_expression
                  (if_table_relation
                    (where_conditions
                      (where_condition
                        field: (identifier)
                        value: (integer)))
                    then_relation: (simple_table_relation
                      table: (identifier))
                    else_relation: (table_relation_expression
                      (if_table_relation
                        (where_conditions
                          (where_condition
                            field: (identifier)
                            value: (integer)))
                        then_relation: (simple_table_relation
                          table: (identifier))
                        else_relation: (table_relation_expression
                          (preproc_conditional_table_relation
                            (preproc_if
                              condition: (identifier))
                            (table_relation_expression
                              (simple_table_relation
                                table: (identifier)))
                            (preproc_else)
                            (table_relation_expression
                              (simple_table_relation
                                table: (identifier)))
                            (preproc_endif)))))))))))
        (trigger_declaration
          (trigger_keyword)
          name: (identifier)
          (code_block
            (call_expression
              function: (identifier)
              arguments: (argument_list
                (string_literal)))))))))
