Skip to content

How to join a distant table with one intermediate table #63

@Naghal

Description

@Naghal

Given the Schema Files -> FilesPaymentAgreements -> FilesPaymentAgreementsDetail, where Files is the master table, is it possible to add define a join for a field on table FilesPaymentAgreementsDetail?

I have tried these two things:

$joins = [
    'FilesPaymentAgreementsDetail.PaymentDate' => [
        'from_table'      => 'FilesPaymentAgreements',
        'from_col'        => 'ID',
        'to_table'        => 'FilesPaymentAgreementsDetail',
        'to_col'          => 'ExID',
        'to_value_column' => 'PaymentDate',
        'to_clause' => function($q) {
            $q->join('FilesPaymentAgreementsDetail', 'FilesPaymentAgreementsDetail.ExID', '=', 'FilesPaymentAgreements.ID');
        },
    ],
];

$qbp = new \timgws\JoinSupportingQueryBuilderParser(['FilesPaymentAgreementsDetail.PaymentDate'], $joins); 
dd($qbp->parse(request()->query_builder, DB::table('Files')->toSql());

Gave me: select * from [Files] where exists (select 1 from [FilesPaymentAgreements] where FilesPaymentAgreements.ExID = Files.ID and [Inactive] = ?) and exists (select 1 from [FilesPaymentAgreements] where FilesPaymentAgreements.ExID = Files.ID and [PaymentMethodID] = ?)

$joins = [
    'FilesPaymentAgreementsDetail.PaymentDate' => [
        [
        'from_table'      => 'Files',
        'from_col'        => 'ID',
        'to_table'        => 'FilesPaymentAgreements',
        'to_col'          => 'ExID',
        'to_value_column' => 'PaymentDate',
        ],
        [
            'from_table'      => 'FilesPaymentAgreements',
            'from_col'        => 'ID',
            'to_table'        => 'FilesPaymentAgreementsDetail',
            'to_col'          => 'ExID',
            'to_value_column' => 'PaymentDate',
        ],
    ],
];

Gave me: "Undefined array key \"to_table\""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions