Hi there,
I'm having an issue when trying to set relations for two fields that are both foreign keys to the same lookup table. Running the code below as-is, I receive the following error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'language'' in F:\Programming\Web\FR\www\GroceryCrud\libraries\zendframework\zend-db\src\Adapter\Driver\Pdo\Connection.php on line 360
The following code works when:
- I remove the N:N relationship, or
- I remove the second setRelation() call, or
- I remove the ['GameID' => $gameID] filter from one of the setRelation() calls
Seems like a bug to me.
My code:
include("libraries/autoload.php");
use GroceryCrud\Core\GroceryCrud;
$database = include('database.php');
$config = include('config.php');
$gameID = $_GET['GID'];
$crud = new GroceryCrud($config, $database);
$crud->setTable('item');
$crud->setSubject('Item', 'Items');
//$crud->where(['item.GameID' => $gameID]);
$crud->setRelationNtoN('Used In Game(s)', 'game_uses_item', 'game', 'ItemID', 'GameID', 'game_shortcode', null, ["GameID" => $gameID]);
$crud->setRelation('ShortNameLanguageID','language','en', ['GameID' => $gameID]);
$crud->setRelation('LongNameLanguageID','language','en', ['GameID' => $gameID]);
$output = $crud->render();
if ($output->isJSONResponse) {
header('Content-Type: application/json; charset=utf-8');
echo $output->output;
exit;
}
$css_files = $output->css_files;
$js_files = $output->js_files;
$output = $output->output;
include('view.php');
