Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Conversation

darylholling
Copy link
Contributor

Further improvement of pull request 736, now also prefix table name alias uses in joins.

@Seb33300
Copy link
Collaborator

Reserved names are already prefixed by the method getEntityShortName.

The logic should not be moved outside of this method.
What is the issue you are trying to fix?
How to reproduce it?

@Seb33300
Copy link
Collaborator

Seb33300 commented Jul 12, 2019

I just looked a little bit deeper in the problem and I think what you should do is:

  • replace the current getEntityShortName by a getSafeName($name) method
  • call the new getSafeName method on line 210 and 263:
$this->entityShortName = $this->getSafeName(strtolower($metadata->getReflectionClass()->getShortName()));
$currentPart = $this->getSafeName(array_shift($parts));

This should fix your issue and this is better to keep he logic in one single method.
Can you try and submit the pull request with this changes?

$data = $this->accessor->getValue($column, 'data');

$currentPart = $this->entityShortName;
$currentPart = $this->getSafeName(array_shift($parts));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not here

*/
private function addJoin($columnTableName, $alias, $type)
{
$alias = $this->getSafeName($alias);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be needed

/**
* @var KeywordList
*/
private $reservedKeywordsList;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, please keep it in the dedicated method as previously

namespace Sg\DatatablesBundle\Response;

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this use is not required anymore


$currentPart = array_shift($parts);
$currentAlias = ($previousPart === $this->entityShortName ? '' : $previousPart.'_').$currentPart;
$currentAlias = ($previousPart === $this->entityShortName ? '' : $previousPart . '_') . $currentPart;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use space between concat

private function getSafeName($name)
{
$entityShortName = strtolower($metadata->getReflectionClass()->getShortName());
$reservedKeywordsList = $this->em->getConnection()->getDatabasePlatform()->getReservedKeywordsList();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should keep this line in the try to catch eventual exceptions


$currentPart = array_shift($parts);
$currentAlias = ($previousPart === $this->entityShortName ? '' : $previousPart.'_').$currentPart;
$currentAlias = ($previousPart === $this->entityShortName ? '' : $previousPart.'_') . $currentPart;
Copy link
Collaborator

@Seb33300 Seb33300 Jul 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forget the last concat ) . $currentPart;

@Seb33300
Copy link
Collaborator

You completely destroyed the code style with your last commit

@darylholling
Copy link
Contributor Author

Oops, fixed it now

@Seb33300
Copy link
Collaborator

This version looks good.
Can you confirm it solves your issue?

@darylholling
Copy link
Contributor Author

Great, I just double checked and it solves my issue.

@Seb33300 Seb33300 merged commit 4e9598d into stwe:master Jul 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants