2012-04-08 3 views
1

Я хотел бы сделать полное внешнее соединение в Doctrine ORM (PHP)Доктрина Полное внешнее объединение

Мой текущий запрос:

$query = Doctrine_Query::create() 
      ->from('Model_Contract_Payment p') 
      ->innerJoin('p.Contract c') 
      ->where(" c.modified_date IS NOT NULL AND (c.modified_date < '" . date(DATABASE_DATE_FORMAT, $lastShowableDate) . "' OR c.archive_status = 1 OR p.archive_status = 1)".$queryStr) 
      ->orderBy($sortColumn . ' ' . $sortDirection); 

Если я этот путь, я получаю только контракты, которые имеет для contract_id и игнорирует данные с payment_id с NULL.

Я бы предпочел, чтобы получить все данные с payment_id NULL

Итак, я хотел бы заменить innerjoin с FULL OUTER JOIN. Любая идея о том, как это сделать?

Мой файл schema.yml:

Contract: 
    connection: doctrine 
    tableName: Contract 
    columns: 
    contract_id: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: true 
    hash: 
     type: string(32) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    payment_id: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: true 
    sales_force_opportunity_id: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    sales_force_opp_owner: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    sales_force_opp_name: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    sales_force_account_name: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    contact_first_name: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    contact_last_name: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    contract_companyname: 
     type: string(80) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    contact_email_address: 
     type: string(256) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    contact_alternate_email_address: 
     type: string(256) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    contact_phone_number: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    contract_status_id: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    contract_agreed_ip_address: 
     type: string(72) 
     fixed: true 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    agreed_date: 
     type: timestamp(16) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    agreement_start_date: 
     type: timestamp(16) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    agreement_end_date: 
     type: timestamp(16) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    seat_details: 
     type: string(2147483647) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    special_instructions: 
     type: string(2147483647) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    agreement_type_id: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    agreement_terms: 
     type: string(2147483647) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    additional_terms: 
     type: string(2147483647) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    additional_notes: 
     type: string(2147483647) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    payment_terms: 
     type: string(2147483647) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    total_value: 
     type: decimal(20) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    payment_method_id: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    bank_name: 
     type: string(100) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    bank_account: 
     type: string(30) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    bank_routing: 
     type: string(30) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_name: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_num_short: 
     type: string(5) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_num_encrypt: 
     type: string(255) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_exp: 
     type: timestamp(16) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_type: 
     type: string(30) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    billing_first_name: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    billing_last_name: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    billing_address1: 
     type: string(100) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    billing_address2: 
     type: string(100) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    billing_city: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    billing_state: 
     type: string(5) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    billing_country: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    billing_postal_code: 
     type: string(20) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    billing_phone: 
     type: string(20) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    shipping_first_name: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    shipping_last_name: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    shipping_address1: 
     type: string(100) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    shipping_address2: 
     type: string(100) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    shipping_city: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    shipping_state: 
     type: string(5) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    shipping_country: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    shipping_postal_code: 
     type: string(20) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    shipping_phone: 
     type: string(20) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    rejection_notes: 
     type: string(2147483647) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    rvp_status_id: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    rvp_comment: 
     type: string(2147483647) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    rvp_id: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    created_date: 
     type: timestamp(16) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    created_admin_id: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    modified_date: 
     type: timestamp(16) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    isenabled: 
     type: boolean(1) 
     fixed: false 
     unsigned: false 
     notnull: true 
     default: 1 
     primary: false 
     autoincrement: false 
    archive_status: 
     type: integer(1) 
     fixed: false 
     unsigned: false 
     notnull: true 
     default: 0 
     primary: false 
     autoincrement: false 
    relations: 
    Contract_Status: 
     local: contract_status_id 
     foreign: contract_status_id 
     type: one 
    Agreement_Type: 
     local: agreement_type_id 
     foreign: agreement_type_id 
     type: one 
    Payment_Method: 
     local: payment_method_id 
     foreign: payment_method_id 
     type: one 
    AdminUser: 
     local: created_admin_id 
     foreign: admin_id 
     type: one 
    Contract_Payment: 
     local: contract_id 
     foreign: contract_id 
     type: many 
     cascade: [delete] 
    Contract_Product: 
     local: contract_id 
     foreign: contract_id 
     type: many 
     cascade: [delete] 
    Contract_Venue: 
     local: contract_id 
     foreign: contract_id 
     type: many 
     cascade: [delete] 
Contract_Payment: 
    connection: doctrine 
    tableName: Contract_Payment 
    columns: 
    payment_id: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: true 
    created_date: 
     type: timestamp(16) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    contract_id: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    payment_status_id: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    amount: 
     type: decimal(20) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_amount: 
     type: decimal(20) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_amount1: 
     type: decimal(20) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    check_amount: 
     type: decimal(20) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    due_date: 
     type: timestamp(16) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    modified_date: 
     type: timestamp(16) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    modified_admin_id: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    notes: 
     type: string(200) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    payment_method_id: 
     type: integer(1) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    payment_status_id_credit_card1: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    payment_status_id_credit_card2: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_holdername: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_num_short: 
     type: string(5) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_num_encrypt: 
     type: string(255) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_expiration: 
     type: timestamp(16) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_type: 
     type: string(30) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    second_credit_card_enable: 
     type: integer(1) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_holdername1: 
     type: string(50) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_num_short1: 
     type: string(5) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_num_encrypt1: 
     type: string(255) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_expiration1: 
     type: timestamp(16) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    credit_card_type1: 
     type: string(30) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    auth_reference: 
     type: string(100) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    auth_reference1: 
     type: string(100) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    billing_postal_code: 
     type: string(20) 
     fixed: false 
     unsigned: false 
     notnull: false 
     primary: false 
     autoincrement: false 
    archive_status: 
     type: integer(1) 
     fixed: false 
     unsigned: false 
     notnull: true 
     default: 0 
     primary: false 
     autoincrement: false 
    relations: 
    Contract: 
     local: contract_id 
     foreign: contract_id 
     type: one 
    Payment_Status: 
     local: payment_status_id 
     foreign: payment_status_id 
     type: one 
    AdminUser: 
     local: modified_admin_id 
     foreign: admin_id 
     type: one 
    Contract_Payment_History: 
     local: payment_id 
     foreign: payment_id 
     type: many 
     cascade: [delete] 

Я использую SQL Server. Любая идея была бы принята с благодарностью! Спасибо

ответ

1

я понял, что полное внешнее объединение не представляется возможным в Doctrine ORM. Итак, я изменил код приложения, чтобы использовать LEFT JOIN.

3

В вашем SQL отсутствует какая-либо ключевая информация, было бы проще, если бы вы разместили SQL-запрос. Но по звукам вы хотите использовать leftJoin вместо innerJoin (LEFT JOIN - это то же самое, что и LEFT OUTER JOIN).

См Coding Horror: A Visual Explanation of SQL Joins для получения дополнительной информации

+0

Я хотел бы реализовать запрос следующим образом: 'выбрать р *, с * от контракта с FULL OUTER JOIN ON (c.contract_id = p.contract_id) ГДЕ c.modified_date НЕ NULL' – Vimalnath

+0

.. Вы используете mysql? У вас не может быть ПОЛНОЕ ВНЕШНЕЕ СОЕДИНЕНИЕ. http://www.artfulsoftware.com/infotree/queries.php#690 – Ashley

+0

Я использую SQL SERVER , и здесь возможно полное внешнее соединение. – Vimalnath

Смежные вопросы