<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="buttonDataflow">

  <!--
    두 테이블 간의 조인 관계 양방향 탐색
    - Node의 getJoinRelationshipBetweenTables 동일 쿼리
    - company_code 처리: companyCode != '*' 이면 (company_code = ? OR company_code = '*') 조건 추가
  -->
  <select id="getButtonDataflowJoinRelationship" parameterType="map" resultType="map">
    SELECT
        FROM_TABLE_NAME
        , FROM_COLUMN_NAME
        , TO_TABLE_NAME
        , TO_COLUMN_NAME
        , RELATIONSHIP_TYPE
        , SETTINGS
    FROM TABLE_RELATIONSHIPS
    WHERE IS_ACTIVE = 'Y'
      AND (
        (FROM_TABLE_NAME = #{main_table}   AND TO_TABLE_NAME = #{detail_table})
        OR
        (FROM_TABLE_NAME = #{detail_table} AND TO_TABLE_NAME = #{main_table})
      )
    <if test='company_code != null and company_code != "*"'>
      AND (COMPANY_CODE = #{company_code} OR COMPANY_CODE = '*')
    </if>
    LIMIT 1
  </select>

</mapper>
