Skip to content

Commit

Permalink
Added support for already aliased parent tables
Browse files Browse the repository at this point in the history
Had a problem with a mjoin on an aliased table. These changes fixed my problem.
  • Loading branch information
gil04 authored Aug 7, 2019
1 parent 2fdf102 commit 8e418d5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Editor/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@ public function data( $editor, &$data, &$options )
$idPrefix = $editor->idPrefix();

$dteTable = $dteTable[0];
if ( strpos($dteTable, ' as ') !== false ) {
$arr = explode(' as ', $dteTable);
$dteTable = $arr[0];
$this->_aliasParentTable = $arr[1];
}

$dteTableLocal = $this->_aliasParentTable ? // Can be aliased to allow a self join
$this->_aliasParentTable :
$dteTable;
Expand All @@ -478,7 +484,7 @@ public function data( $editor, &$data, &$options )

if ( count($data) > 0 ) {
$pkey = $pkey[0];
$pkeyIsJoin = $pkey === $joinField || $pkey === $dteTable.'.'.$joinField;
$pkeyIsJoin = $pkey === $joinField || $pkey === $dteTableLocal.'.'.$joinField;

// Sanity check that table selector fields are read only, and have an name without
// a dot (for DataTables mData to be able to read it)
Expand Down Expand Up @@ -876,6 +882,11 @@ private function _prep ( $editor )
$editorTable = $editor->table();
$editorTable = $editorTable[0];
$joinTable = $this->table();
if ( strpos($editorTable, ' as ') !== false ) {
$arr = explode(' as ', $editorTable);
$editorTable = $arr[0];
$this->_aliasParentTable = $arr[1];
}

if ( $this->_aliasParentTable ) {
$editorTable = $this->_aliasParentTable;
Expand Down

0 comments on commit 8e418d5

Please sign in to comment.