Added correct behavior to Tweaking Joint relationships in the dynamicGet compiler method setGetData. gh-500

This commit is contained in:
Llewellyn van der Merwe 2019-12-16 05:02:16 +02:00
parent 9f6e0c49da
commit 2ed53b2a3b
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
4 changed files with 52 additions and 14 deletions

View File

@ -144,7 +144,7 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 13th December, 2019 + *Last Build*: 16th December, 2019
+ *Version*: 2.10.9 + *Version*: 2.10.9
+ *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt

View File

@ -144,7 +144,7 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 13th December, 2019 + *Last Build*: 16th December, 2019
+ *Version*: 2.10.9 + *Version*: 2.10.9
+ *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt

View File

@ -3603,6 +3603,26 @@ class Get
$result->join_view_table = json_decode($result->join_view_table, true); $result->join_view_table = json_decode($result->join_view_table, true);
if (ComponentbuilderHelper::checkArray($result->join_view_table)) if (ComponentbuilderHelper::checkArray($result->join_view_table))
{ {
// start the part of a table bucket
$_part_of_a = array();
// build relationship
$_relationship = array_map(function($op) use(&$_part_of_a){
$bucket = array();
// array(on_field_as, on_field)
$bucket['on_field'] = array_map('trim', explode('.', $op['on_field']));
// array(join_field_as, join_field)
$bucket['join_field'] = array_map('trim', explode('.', $op['join_field']));
// triget filed that has table a relationship
if ($bucket['on_field'][0] === 'a' ||
isset($_part_of_a[$bucket['on_field'][0]]) ||
isset($_part_of_a[$bucket['join_field'][0]]))
{
$_part_of_a[$op['as']] = $op['as'];
}
return $bucket;
}, $result->join_view_table);
// loop joints
foreach ($result->join_view_table as $nr => &$option) foreach ($result->join_view_table as $nr => &$option)
{ {
if (ComponentbuilderHelper::checkString($option['selection'])) if (ComponentbuilderHelper::checkString($option['selection']))
@ -3612,11 +3632,10 @@ class Get
// convert the operator // convert the operator
$option['operator'] = $operatorArray[$option['operator']]; $option['operator'] = $operatorArray[$option['operator']];
// get the on field values // get the on field values
$on_field = array(); // array(on_field_as, on_field) $on_field = $_relationship[$nr]['on_field'];
$on_field = array_map('trim', explode('.', $option['on_field']));
// get the join field values // get the join field values
$join_field = array(); // array(join_field_as, join_field) $join_field = $_relationship[$nr]['join_field'];
$join_field = array_map('trim', explode('.', $option['join_field'])); // set selection
$option['selection'] = $this->setDataSelection($result->key, $view_code, $option['selection'], $option['view_table'], $option['as'], $option['row_type'], 'view'); $option['selection'] = $this->setDataSelection($result->key, $view_code, $option['selection'], $option['view_table'], $option['as'], $option['row_type'], 'view');
$option['key'] = $result->key; $option['key'] = $result->key;
$option['context'] = $context; $option['context'] = $context;
@ -3624,7 +3643,7 @@ class Get
if ($option['row_type'] == 1) if ($option['row_type'] == 1)
{ {
$result->main_get[] = $option; $result->main_get[] = $option;
if ($on_field[0] === 'a') if ($on_field[0] === 'a' || isset($_part_of_a[$join_field[0]]) || isset($_part_of_a[$on_field[0]]))
{ {
$this->siteMainGet[$this->target][$view_code][$option['as']] = $option['as']; $this->siteMainGet[$this->target][$view_code][$option['as']] = $option['as'];
} }
@ -3650,6 +3669,26 @@ class Get
$result->join_db_table = json_decode($result->join_db_table, true); $result->join_db_table = json_decode($result->join_db_table, true);
if (ComponentbuilderHelper::checkArray($result->join_db_table)) if (ComponentbuilderHelper::checkArray($result->join_db_table))
{ {
// start the part of a table bucket
$_part_of_a = array();
// build relationship
$_relationship = array_map(function($op) use(&$_part_of_a){
$bucket = array();
// array(on_field_as, on_field)
$bucket['on_field'] = array_map('trim', explode('.', $op['on_field']));
// array(join_field_as, join_field)
$bucket['join_field'] = array_map('trim', explode('.', $op['join_field']));
// triget filed that has table a relationship
if ($bucket['on_field'][0] === 'a' ||
isset($_part_of_a[$bucket['on_field'][0]]) ||
isset($_part_of_a[$bucket['join_field'][0]]))
{
$_part_of_a[$op['as']] = $op['as'];
}
return $bucket;
}, $result->join_db_table);
// loop joints
foreach ($result->join_db_table as $nr => &$option1) foreach ($result->join_db_table as $nr => &$option1)
{ {
if (ComponentbuilderHelper::checkString($option1['selection'])) if (ComponentbuilderHelper::checkString($option1['selection']))
@ -3659,11 +3698,10 @@ class Get
// convert the operator // convert the operator
$option1['operator'] = $operatorArray[$option1['operator']]; $option1['operator'] = $operatorArray[$option1['operator']];
// get the on field values // get the on field values
$on_field = array(); // array(on_field_as, on_field) $on_field = $_relationship[$nr]['on_field'];
$on_field = array_map('trim', explode('.', $option1['on_field']));
// get the join field values // get the join field values
$join_field = array(); // array(join_field_as, join_field) $join_field = $_relationship[$nr]['join_field'];
$join_field = array_map('trim', explode('.', $option1['join_field'])); // set selection
$option1['selection'] = $this->setDataSelection($result->key, $view_code, $option1['selection'], $option1['db_table'], $option1['as'], $option1['row_type'], 'db'); $option1['selection'] = $this->setDataSelection($result->key, $view_code, $option1['selection'], $option1['db_table'], $option1['as'], $option1['row_type'], 'db');
$option1['key'] = $result->key; $option1['key'] = $result->key;
$option1['context'] = $context; $option1['context'] = $context;
@ -3671,7 +3709,7 @@ class Get
if ($option1['row_type'] == 1) if ($option1['row_type'] == 1)
{ {
$result->main_get[] = $option1; $result->main_get[] = $option1;
if ($on_field[0] === 'a') if ($on_field[0] === 'a' || isset($_part_of_a[$join_field[0]]) || isset($_part_of_a[$on_field[0]]))
{ {
$this->siteMainGet[$this->target][$view_code][$option1['as']] = $option1['as']; $this->siteMainGet[$this->target][$view_code][$option1['as']] = $option1['as'];
} }
@ -5001,7 +5039,7 @@ class Get
if (ComponentbuilderHelper::checkArray($gets) && ComponentbuilderHelper::checkArray($keys)) if (ComponentbuilderHelper::checkArray($gets) && ComponentbuilderHelper::checkArray($keys))
{ {
// single joined selection needs the prefix to the values to avoid conflict in the names // single joined selection needs the prefix to the values to avoid conflict in the names
// so we most still add then AS // so we must still add then AS
if ($string == '*' && 1 != $row_type) if ($string == '*' && 1 != $row_type)
{ {
$querySelect = "\$query->select('" . $as . ".*');"; $querySelect = "\$query->select('" . $as . ".*');";

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2" method="upgrade"> <extension type="component" version="3.2" method="upgrade">
<name>COM_COMPONENTBUILDER</name> <name>COM_COMPONENTBUILDER</name>
<creationDate>13th December, 2019</creationDate> <creationDate>16th December, 2019</creationDate>
<author>Llewellyn van der Merwe</author> <author>Llewellyn van der Merwe</author>
<authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail> <authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail>
<authorUrl>http://www.joomlacomponentbuilder.com</authorUrl> <authorUrl>http://www.joomlacomponentbuilder.com</authorUrl>