Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 168 Vote(s) - 3.35 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check if alias exists?

#1
How I could check if the alias is already defined?

There is no method for check this.


Thats not working because I got only the ROOT alias and no join aliases.

/** @var $query \Doctrine\ORM\QueryBuilder */
$query->getRootAliases()

The parts is another invalid option for me...

$query->getDQLPart()

Returns only the parts like "select, from, etc.".

And thats the error I would "ignore".

[Semantical Error] line 0, col 254 near '_user LEFT': Error: '_user' is already defined.


**How could I check if the alias exists?**
Reply

#2
You get this error because you're trying to join with an already defined alias.

A solution would be to check join DQL parts. In your repository method you could do something like this:


$joinDqlParts = $queryBuilder->getDQLParts()['join'];
$aliasAlreadyExists = false;

/* @var $join Query\Expr\Join */
foreach ($joinDqlParts as $joins) {
foreach ($joins as $join) {
if ($join->getAlias() === '_user') {
$aliasAlreadyExists = true;
break 2;
}
}
}

if ($aliasAlreadyExists === false) {
$queryBuilder->innerJoin('parenttable._user', '_user')

}


So you only join if you didn't joined already.
Reply

#3
You could use PHP native `in_array` function to check if the value exists in the array or not.

in_array($alias, $qb->getAllAliases())
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through