Yii2 - Syntax error or access violation: 1066 Not unique table











up vote
-1
down vote

favorite












I'm trying to join two tables in a query :






- sc_cours -
idCour
volHoraireCour
idMat

- sc_matieres -
idMat
nomMat





the code of the query is the following






$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat');





But i get this following error






SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'sc_matieres' non unique
The SQL being executed was: SELECT * FROM `sc_cours` INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat





Do you know what's the main problem guys? Thanks you!










share|improve this question







New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Try this - $query = new yiidbQuery(); $query->select(['a.*','b.*']) ->from(['a' => 'sc_cours']) ->innerJoin(['b' => 'sc_matieres'],'a.idMat = b.idMat') ->all();
    – Gru
    yesterday












  • I have the same error, but this time on the aliases Syntax error or access violation: 1066 Table/alias: 'b' non unique The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN sc_matieres b ON a.idMat = b.idMat INNER JOIN sc_matieres b ON a.idMat = b.idMat
    – Badara
    yesterday

















up vote
-1
down vote

favorite












I'm trying to join two tables in a query :






- sc_cours -
idCour
volHoraireCour
idMat

- sc_matieres -
idMat
nomMat





the code of the query is the following






$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat');





But i get this following error






SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'sc_matieres' non unique
The SQL being executed was: SELECT * FROM `sc_cours` INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat





Do you know what's the main problem guys? Thanks you!










share|improve this question







New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Try this - $query = new yiidbQuery(); $query->select(['a.*','b.*']) ->from(['a' => 'sc_cours']) ->innerJoin(['b' => 'sc_matieres'],'a.idMat = b.idMat') ->all();
    – Gru
    yesterday












  • I have the same error, but this time on the aliases Syntax error or access violation: 1066 Table/alias: 'b' non unique The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN sc_matieres b ON a.idMat = b.idMat INNER JOIN sc_matieres b ON a.idMat = b.idMat
    – Badara
    yesterday















up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I'm trying to join two tables in a query :






- sc_cours -
idCour
volHoraireCour
idMat

- sc_matieres -
idMat
nomMat





the code of the query is the following






$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat');





But i get this following error






SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'sc_matieres' non unique
The SQL being executed was: SELECT * FROM `sc_cours` INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat





Do you know what's the main problem guys? Thanks you!










share|improve this question







New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I'm trying to join two tables in a query :






- sc_cours -
idCour
volHoraireCour
idMat

- sc_matieres -
idMat
nomMat





the code of the query is the following






$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat');





But i get this following error






SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'sc_matieres' non unique
The SQL being executed was: SELECT * FROM `sc_cours` INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat





Do you know what's the main problem guys? Thanks you!






- sc_cours -
idCour
volHoraireCour
idMat

- sc_matieres -
idMat
nomMat





- sc_cours -
idCour
volHoraireCour
idMat

- sc_matieres -
idMat
nomMat





$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat');





$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat');





SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'sc_matieres' non unique
The SQL being executed was: SELECT * FROM `sc_cours` INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat





SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'sc_matieres' non unique
The SQL being executed was: SELECT * FROM `sc_cours` INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat INNER JOIN `sc_matieres` ON sc_cours.idMat = sc_matieres.idMat






yii2






share|improve this question







New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Badara

1




1




New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Try this - $query = new yiidbQuery(); $query->select(['a.*','b.*']) ->from(['a' => 'sc_cours']) ->innerJoin(['b' => 'sc_matieres'],'a.idMat = b.idMat') ->all();
    – Gru
    yesterday












  • I have the same error, but this time on the aliases Syntax error or access violation: 1066 Table/alias: 'b' non unique The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN sc_matieres b ON a.idMat = b.idMat INNER JOIN sc_matieres b ON a.idMat = b.idMat
    – Badara
    yesterday




















  • Try this - $query = new yiidbQuery(); $query->select(['a.*','b.*']) ->from(['a' => 'sc_cours']) ->innerJoin(['b' => 'sc_matieres'],'a.idMat = b.idMat') ->all();
    – Gru
    yesterday












  • I have the same error, but this time on the aliases Syntax error or access violation: 1066 Table/alias: 'b' non unique The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN sc_matieres b ON a.idMat = b.idMat INNER JOIN sc_matieres b ON a.idMat = b.idMat
    – Badara
    yesterday


















Try this - $query = new yiidbQuery(); $query->select(['a.*','b.*']) ->from(['a' => 'sc_cours']) ->innerJoin(['b' => 'sc_matieres'],'a.idMat = b.idMat') ->all();
– Gru
yesterday






Try this - $query = new yiidbQuery(); $query->select(['a.*','b.*']) ->from(['a' => 'sc_cours']) ->innerJoin(['b' => 'sc_matieres'],'a.idMat = b.idMat') ->all();
– Gru
yesterday














I have the same error, but this time on the aliases Syntax error or access violation: 1066 Table/alias: 'b' non unique The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN sc_matieres b ON a.idMat = b.idMat INNER JOIN sc_matieres b ON a.idMat = b.idMat
– Badara
yesterday






I have the same error, but this time on the aliases Syntax error or access violation: 1066 Table/alias: 'b' non unique The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN sc_matieres b ON a.idMat = b.idMat INNER JOIN sc_matieres b ON a.idMat = b.idMat
– Badara
yesterday














2 Answers
2






active

oldest

votes

















up vote
0
down vote













From error you can see that you have two inner joins exact same. Define relation in model and than just do ->innerJoin('nameOfRelation');






share|improve this answer





















  • There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
    – Badara
    yesterday












  • why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
    – Borisa Eric
    18 hours ago










  • sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
    – Badara
    16 hours ago












  • No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
    – Borisa Eric
    15 hours ago










  • ok i've posted all the code
    – Badara
    13 hours ago




















up vote
0
down vote













ok So the model of Sc_cours






<?php

namespace appmodels;

use Yii;

/**
* This is the model class for table "sc_cours" => ScCours.
*
* @property int $idCour
* @property string $heureDebCour
* @property string $heureFinCour
* @property int $jourCour
* @property int $volHoraireCour
* @property int $partieCour
* @property string $semestreCour
* @property int $sharedCour
* @property int $idMat
*
* @property ScMatieres $mat
* @property ScHoraires $scHoraires
*/
class ScCours extends yiidbActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'sc_cours';
}

/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['heureDebCour', 'heureFinCour', 'jourCour', 'volHoraireCour', 'partieCour', 'semestreCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'required'],
[['jourCour', 'volHoraireCour', 'partieCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'integer'],
[['semestreCour'], 'string'],
[['heureDebCour', 'heureFinCour'], 'string', 'max' => 255],
[['idMat'], 'exist', 'skipOnError' => true, 'targetClass' => ScMatieres::className(), 'targetAttribute' => ['idMat' => 'idMat']],
];
}

/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'idCour' => 'Id Cour',
'heureDebCour' => 'Début Cour',
'heureFinCour' => 'Fin Cour',
'jourCour' => 'Jour',
'volHoraireCour' => 'Volume Horaire',
'partieCour' => 'Partie',
'semestreCour' => 'Semestre',
'sharedCour' => 'Partagé ?',
'idMat' => 'Matière',
];
}

/**
* @return yiidbActiveQuery
*/
public function getMat()
{
return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']);
}

/**
* @return yiidbActiveQuery
*/
public function getScHoraires()
{
return $this->hasMany(ScHoraires::className(), ['idCour' => 'idCour']);
}
}





But the treatment , i do it in a global function , so i've created a component that is inclued in config/web.php






<?php
/**
* Created by PhpStorm.
* User: Badara
* Date: 21/11/2018
* Time: 02:16
*/
namespace appcomponents;


use appmodelsScCours;
use appmodelsScMatieres;
use Yii;
use yiibaseComponent;
use yiibaseInvalidConfigException;
use yiidbQuery;
use yiihelpersUrl;

class MyGFunctions extends Component{

public function show($partie, $semestre){
$request = Yii::$app->request;
$id = $request->get('id');

$query = new Query;
for ($i = 1; $i <= 6; $i++){
$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat')
->where(['partieCour' => $partie, 'semestreCour' => $semestre, 'idClasse' => $id, 'jourCour' => $i ]);

$cours = $query->all();
if ($cours){
echo "Get them"
}
}else{
echo 'Get nothing';
}
}

}
}





Now when i change ->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat'); to ->innerJoin('mat'); It will take mat as a table...






share|improve this answer








New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • Ok, I see problem. Relation is invoked on instance of Query class and Query class cannot handle this relation. Try with ScCours::find()->join('mat')
    – Borisa Eric
    2 hours ago













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Badara is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404609%2fyii2-syntax-error-or-access-violation-1066-not-unique-table%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













From error you can see that you have two inner joins exact same. Define relation in model and than just do ->innerJoin('nameOfRelation');






share|improve this answer





















  • There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
    – Badara
    yesterday












  • why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
    – Borisa Eric
    18 hours ago










  • sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
    – Badara
    16 hours ago












  • No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
    – Borisa Eric
    15 hours ago










  • ok i've posted all the code
    – Badara
    13 hours ago

















up vote
0
down vote













From error you can see that you have two inner joins exact same. Define relation in model and than just do ->innerJoin('nameOfRelation');






share|improve this answer





















  • There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
    – Badara
    yesterday












  • why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
    – Borisa Eric
    18 hours ago










  • sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
    – Badara
    16 hours ago












  • No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
    – Borisa Eric
    15 hours ago










  • ok i've posted all the code
    – Badara
    13 hours ago















up vote
0
down vote










up vote
0
down vote









From error you can see that you have two inner joins exact same. Define relation in model and than just do ->innerJoin('nameOfRelation');






share|improve this answer












From error you can see that you have two inner joins exact same. Define relation in model and than just do ->innerJoin('nameOfRelation');







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Borisa Eric

28416




28416












  • There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
    – Badara
    yesterday












  • why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
    – Borisa Eric
    18 hours ago










  • sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
    – Badara
    16 hours ago












  • No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
    – Borisa Eric
    15 hours ago










  • ok i've posted all the code
    – Badara
    13 hours ago




















  • There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
    – Badara
    yesterday












  • why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
    – Borisa Eric
    18 hours ago










  • sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
    – Badara
    16 hours ago












  • No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
    – Borisa Eric
    15 hours ago










  • ok i've posted all the code
    – Badara
    13 hours ago


















There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
– Badara
yesterday






There's already the relation in the model public function getMat() { return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']); } but if i do ->innerJoin('classe) , it wil take the nameofRelation as a table ... Base table or view not found: 1146 La table 's'coolapp.classe' n'existe pas The SQL being executed was: SELECT * FROM sc_cours a INNER JOIN classe
– Badara
yesterday














why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
– Borisa Eric
18 hours ago




why classe if your relation name is getMat() then your relation should be mat and it would take from tabel defined in ScMatieres
– Borisa Eric
18 hours ago












sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
– Badara
16 hours ago






sorry it's me who do an error here (it just because i do the same with another tables sc_classes , sorry for that again ...) but unfortunately even if i write mat , i get the same error, telling me that the table mat does not exist
– Badara
16 hours ago














No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
– Borisa Eric
15 hours ago




No need for saying sorry, we are here to help each other. It should not get table name from relation, instead it should take table name from ScMatieres. Can you provide all code related to this issue.
– Borisa Eric
15 hours ago












ok i've posted all the code
– Badara
13 hours ago






ok i've posted all the code
– Badara
13 hours ago














up vote
0
down vote













ok So the model of Sc_cours






<?php

namespace appmodels;

use Yii;

/**
* This is the model class for table "sc_cours" => ScCours.
*
* @property int $idCour
* @property string $heureDebCour
* @property string $heureFinCour
* @property int $jourCour
* @property int $volHoraireCour
* @property int $partieCour
* @property string $semestreCour
* @property int $sharedCour
* @property int $idMat
*
* @property ScMatieres $mat
* @property ScHoraires $scHoraires
*/
class ScCours extends yiidbActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'sc_cours';
}

/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['heureDebCour', 'heureFinCour', 'jourCour', 'volHoraireCour', 'partieCour', 'semestreCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'required'],
[['jourCour', 'volHoraireCour', 'partieCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'integer'],
[['semestreCour'], 'string'],
[['heureDebCour', 'heureFinCour'], 'string', 'max' => 255],
[['idMat'], 'exist', 'skipOnError' => true, 'targetClass' => ScMatieres::className(), 'targetAttribute' => ['idMat' => 'idMat']],
];
}

/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'idCour' => 'Id Cour',
'heureDebCour' => 'Début Cour',
'heureFinCour' => 'Fin Cour',
'jourCour' => 'Jour',
'volHoraireCour' => 'Volume Horaire',
'partieCour' => 'Partie',
'semestreCour' => 'Semestre',
'sharedCour' => 'Partagé ?',
'idMat' => 'Matière',
];
}

/**
* @return yiidbActiveQuery
*/
public function getMat()
{
return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']);
}

/**
* @return yiidbActiveQuery
*/
public function getScHoraires()
{
return $this->hasMany(ScHoraires::className(), ['idCour' => 'idCour']);
}
}





But the treatment , i do it in a global function , so i've created a component that is inclued in config/web.php






<?php
/**
* Created by PhpStorm.
* User: Badara
* Date: 21/11/2018
* Time: 02:16
*/
namespace appcomponents;


use appmodelsScCours;
use appmodelsScMatieres;
use Yii;
use yiibaseComponent;
use yiibaseInvalidConfigException;
use yiidbQuery;
use yiihelpersUrl;

class MyGFunctions extends Component{

public function show($partie, $semestre){
$request = Yii::$app->request;
$id = $request->get('id');

$query = new Query;
for ($i = 1; $i <= 6; $i++){
$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat')
->where(['partieCour' => $partie, 'semestreCour' => $semestre, 'idClasse' => $id, 'jourCour' => $i ]);

$cours = $query->all();
if ($cours){
echo "Get them"
}
}else{
echo 'Get nothing';
}
}

}
}





Now when i change ->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat'); to ->innerJoin('mat'); It will take mat as a table...






share|improve this answer








New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • Ok, I see problem. Relation is invoked on instance of Query class and Query class cannot handle this relation. Try with ScCours::find()->join('mat')
    – Borisa Eric
    2 hours ago

















up vote
0
down vote













ok So the model of Sc_cours






<?php

namespace appmodels;

use Yii;

/**
* This is the model class for table "sc_cours" => ScCours.
*
* @property int $idCour
* @property string $heureDebCour
* @property string $heureFinCour
* @property int $jourCour
* @property int $volHoraireCour
* @property int $partieCour
* @property string $semestreCour
* @property int $sharedCour
* @property int $idMat
*
* @property ScMatieres $mat
* @property ScHoraires $scHoraires
*/
class ScCours extends yiidbActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'sc_cours';
}

/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['heureDebCour', 'heureFinCour', 'jourCour', 'volHoraireCour', 'partieCour', 'semestreCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'required'],
[['jourCour', 'volHoraireCour', 'partieCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'integer'],
[['semestreCour'], 'string'],
[['heureDebCour', 'heureFinCour'], 'string', 'max' => 255],
[['idMat'], 'exist', 'skipOnError' => true, 'targetClass' => ScMatieres::className(), 'targetAttribute' => ['idMat' => 'idMat']],
];
}

/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'idCour' => 'Id Cour',
'heureDebCour' => 'Début Cour',
'heureFinCour' => 'Fin Cour',
'jourCour' => 'Jour',
'volHoraireCour' => 'Volume Horaire',
'partieCour' => 'Partie',
'semestreCour' => 'Semestre',
'sharedCour' => 'Partagé ?',
'idMat' => 'Matière',
];
}

/**
* @return yiidbActiveQuery
*/
public function getMat()
{
return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']);
}

/**
* @return yiidbActiveQuery
*/
public function getScHoraires()
{
return $this->hasMany(ScHoraires::className(), ['idCour' => 'idCour']);
}
}





But the treatment , i do it in a global function , so i've created a component that is inclued in config/web.php






<?php
/**
* Created by PhpStorm.
* User: Badara
* Date: 21/11/2018
* Time: 02:16
*/
namespace appcomponents;


use appmodelsScCours;
use appmodelsScMatieres;
use Yii;
use yiibaseComponent;
use yiibaseInvalidConfigException;
use yiidbQuery;
use yiihelpersUrl;

class MyGFunctions extends Component{

public function show($partie, $semestre){
$request = Yii::$app->request;
$id = $request->get('id');

$query = new Query;
for ($i = 1; $i <= 6; $i++){
$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat')
->where(['partieCour' => $partie, 'semestreCour' => $semestre, 'idClasse' => $id, 'jourCour' => $i ]);

$cours = $query->all();
if ($cours){
echo "Get them"
}
}else{
echo 'Get nothing';
}
}

}
}





Now when i change ->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat'); to ->innerJoin('mat'); It will take mat as a table...






share|improve this answer








New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • Ok, I see problem. Relation is invoked on instance of Query class and Query class cannot handle this relation. Try with ScCours::find()->join('mat')
    – Borisa Eric
    2 hours ago















up vote
0
down vote










up vote
0
down vote









ok So the model of Sc_cours






<?php

namespace appmodels;

use Yii;

/**
* This is the model class for table "sc_cours" => ScCours.
*
* @property int $idCour
* @property string $heureDebCour
* @property string $heureFinCour
* @property int $jourCour
* @property int $volHoraireCour
* @property int $partieCour
* @property string $semestreCour
* @property int $sharedCour
* @property int $idMat
*
* @property ScMatieres $mat
* @property ScHoraires $scHoraires
*/
class ScCours extends yiidbActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'sc_cours';
}

/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['heureDebCour', 'heureFinCour', 'jourCour', 'volHoraireCour', 'partieCour', 'semestreCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'required'],
[['jourCour', 'volHoraireCour', 'partieCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'integer'],
[['semestreCour'], 'string'],
[['heureDebCour', 'heureFinCour'], 'string', 'max' => 255],
[['idMat'], 'exist', 'skipOnError' => true, 'targetClass' => ScMatieres::className(), 'targetAttribute' => ['idMat' => 'idMat']],
];
}

/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'idCour' => 'Id Cour',
'heureDebCour' => 'Début Cour',
'heureFinCour' => 'Fin Cour',
'jourCour' => 'Jour',
'volHoraireCour' => 'Volume Horaire',
'partieCour' => 'Partie',
'semestreCour' => 'Semestre',
'sharedCour' => 'Partagé ?',
'idMat' => 'Matière',
];
}

/**
* @return yiidbActiveQuery
*/
public function getMat()
{
return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']);
}

/**
* @return yiidbActiveQuery
*/
public function getScHoraires()
{
return $this->hasMany(ScHoraires::className(), ['idCour' => 'idCour']);
}
}





But the treatment , i do it in a global function , so i've created a component that is inclued in config/web.php






<?php
/**
* Created by PhpStorm.
* User: Badara
* Date: 21/11/2018
* Time: 02:16
*/
namespace appcomponents;


use appmodelsScCours;
use appmodelsScMatieres;
use Yii;
use yiibaseComponent;
use yiibaseInvalidConfigException;
use yiidbQuery;
use yiihelpersUrl;

class MyGFunctions extends Component{

public function show($partie, $semestre){
$request = Yii::$app->request;
$id = $request->get('id');

$query = new Query;
for ($i = 1; $i <= 6; $i++){
$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat')
->where(['partieCour' => $partie, 'semestreCour' => $semestre, 'idClasse' => $id, 'jourCour' => $i ]);

$cours = $query->all();
if ($cours){
echo "Get them"
}
}else{
echo 'Get nothing';
}
}

}
}





Now when i change ->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat'); to ->innerJoin('mat'); It will take mat as a table...






share|improve this answer








New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









ok So the model of Sc_cours






<?php

namespace appmodels;

use Yii;

/**
* This is the model class for table "sc_cours" => ScCours.
*
* @property int $idCour
* @property string $heureDebCour
* @property string $heureFinCour
* @property int $jourCour
* @property int $volHoraireCour
* @property int $partieCour
* @property string $semestreCour
* @property int $sharedCour
* @property int $idMat
*
* @property ScMatieres $mat
* @property ScHoraires $scHoraires
*/
class ScCours extends yiidbActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'sc_cours';
}

/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['heureDebCour', 'heureFinCour', 'jourCour', 'volHoraireCour', 'partieCour', 'semestreCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'required'],
[['jourCour', 'volHoraireCour', 'partieCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'integer'],
[['semestreCour'], 'string'],
[['heureDebCour', 'heureFinCour'], 'string', 'max' => 255],
[['idMat'], 'exist', 'skipOnError' => true, 'targetClass' => ScMatieres::className(), 'targetAttribute' => ['idMat' => 'idMat']],
];
}

/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'idCour' => 'Id Cour',
'heureDebCour' => 'Début Cour',
'heureFinCour' => 'Fin Cour',
'jourCour' => 'Jour',
'volHoraireCour' => 'Volume Horaire',
'partieCour' => 'Partie',
'semestreCour' => 'Semestre',
'sharedCour' => 'Partagé ?',
'idMat' => 'Matière',
];
}

/**
* @return yiidbActiveQuery
*/
public function getMat()
{
return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']);
}

/**
* @return yiidbActiveQuery
*/
public function getScHoraires()
{
return $this->hasMany(ScHoraires::className(), ['idCour' => 'idCour']);
}
}





But the treatment , i do it in a global function , so i've created a component that is inclued in config/web.php






<?php
/**
* Created by PhpStorm.
* User: Badara
* Date: 21/11/2018
* Time: 02:16
*/
namespace appcomponents;


use appmodelsScCours;
use appmodelsScMatieres;
use Yii;
use yiibaseComponent;
use yiibaseInvalidConfigException;
use yiidbQuery;
use yiihelpersUrl;

class MyGFunctions extends Component{

public function show($partie, $semestre){
$request = Yii::$app->request;
$id = $request->get('id');

$query = new Query;
for ($i = 1; $i <= 6; $i++){
$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat')
->where(['partieCour' => $partie, 'semestreCour' => $semestre, 'idClasse' => $id, 'jourCour' => $i ]);

$cours = $query->all();
if ($cours){
echo "Get them"
}
}else{
echo 'Get nothing';
}
}

}
}





Now when i change ->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat'); to ->innerJoin('mat'); It will take mat as a table...






<?php

namespace appmodels;

use Yii;

/**
* This is the model class for table "sc_cours" => ScCours.
*
* @property int $idCour
* @property string $heureDebCour
* @property string $heureFinCour
* @property int $jourCour
* @property int $volHoraireCour
* @property int $partieCour
* @property string $semestreCour
* @property int $sharedCour
* @property int $idMat
*
* @property ScMatieres $mat
* @property ScHoraires $scHoraires
*/
class ScCours extends yiidbActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'sc_cours';
}

/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['heureDebCour', 'heureFinCour', 'jourCour', 'volHoraireCour', 'partieCour', 'semestreCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'required'],
[['jourCour', 'volHoraireCour', 'partieCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'integer'],
[['semestreCour'], 'string'],
[['heureDebCour', 'heureFinCour'], 'string', 'max' => 255],
[['idMat'], 'exist', 'skipOnError' => true, 'targetClass' => ScMatieres::className(), 'targetAttribute' => ['idMat' => 'idMat']],
];
}

/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'idCour' => 'Id Cour',
'heureDebCour' => 'Début Cour',
'heureFinCour' => 'Fin Cour',
'jourCour' => 'Jour',
'volHoraireCour' => 'Volume Horaire',
'partieCour' => 'Partie',
'semestreCour' => 'Semestre',
'sharedCour' => 'Partagé ?',
'idMat' => 'Matière',
];
}

/**
* @return yiidbActiveQuery
*/
public function getMat()
{
return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']);
}

/**
* @return yiidbActiveQuery
*/
public function getScHoraires()
{
return $this->hasMany(ScHoraires::className(), ['idCour' => 'idCour']);
}
}





<?php

namespace appmodels;

use Yii;

/**
* This is the model class for table "sc_cours" => ScCours.
*
* @property int $idCour
* @property string $heureDebCour
* @property string $heureFinCour
* @property int $jourCour
* @property int $volHoraireCour
* @property int $partieCour
* @property string $semestreCour
* @property int $sharedCour
* @property int $idMat
*
* @property ScMatieres $mat
* @property ScHoraires $scHoraires
*/
class ScCours extends yiidbActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'sc_cours';
}

/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['heureDebCour', 'heureFinCour', 'jourCour', 'volHoraireCour', 'partieCour', 'semestreCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'required'],
[['jourCour', 'volHoraireCour', 'partieCour', 'sharedCour', 'idClasse', 'idMat', 'idProf', 'idSalle'], 'integer'],
[['semestreCour'], 'string'],
[['heureDebCour', 'heureFinCour'], 'string', 'max' => 255],
[['idMat'], 'exist', 'skipOnError' => true, 'targetClass' => ScMatieres::className(), 'targetAttribute' => ['idMat' => 'idMat']],
];
}

/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'idCour' => 'Id Cour',
'heureDebCour' => 'Début Cour',
'heureFinCour' => 'Fin Cour',
'jourCour' => 'Jour',
'volHoraireCour' => 'Volume Horaire',
'partieCour' => 'Partie',
'semestreCour' => 'Semestre',
'sharedCour' => 'Partagé ?',
'idMat' => 'Matière',
];
}

/**
* @return yiidbActiveQuery
*/
public function getMat()
{
return $this->hasOne(ScMatieres::className(), ['idMat' => 'idMat']);
}

/**
* @return yiidbActiveQuery
*/
public function getScHoraires()
{
return $this->hasMany(ScHoraires::className(), ['idCour' => 'idCour']);
}
}





<?php
/**
* Created by PhpStorm.
* User: Badara
* Date: 21/11/2018
* Time: 02:16
*/
namespace appcomponents;


use appmodelsScCours;
use appmodelsScMatieres;
use Yii;
use yiibaseComponent;
use yiibaseInvalidConfigException;
use yiidbQuery;
use yiihelpersUrl;

class MyGFunctions extends Component{

public function show($partie, $semestre){
$request = Yii::$app->request;
$id = $request->get('id');

$query = new Query;
for ($i = 1; $i <= 6; $i++){
$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat')
->where(['partieCour' => $partie, 'semestreCour' => $semestre, 'idClasse' => $id, 'jourCour' => $i ]);

$cours = $query->all();
if ($cours){
echo "Get them"
}
}else{
echo 'Get nothing';
}
}

}
}





<?php
/**
* Created by PhpStorm.
* User: Badara
* Date: 21/11/2018
* Time: 02:16
*/
namespace appcomponents;


use appmodelsScCours;
use appmodelsScMatieres;
use Yii;
use yiibaseComponent;
use yiibaseInvalidConfigException;
use yiidbQuery;
use yiihelpersUrl;

class MyGFunctions extends Component{

public function show($partie, $semestre){
$request = Yii::$app->request;
$id = $request->get('id');

$query = new Query;
for ($i = 1; $i <= 6; $i++){
$query->select('*')
->from('sc_cours')
->innerJoin('sc_matieres', 'sc_cours.idMat = sc_matieres.idMat')
->where(['partieCour' => $partie, 'semestreCour' => $semestre, 'idClasse' => $id, 'jourCour' => $i ]);

$cours = $query->all();
if ($cours){
echo "Get them"
}
}else{
echo 'Get nothing';
}
}

}
}






share|improve this answer








New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer






New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered 13 hours ago









Badara

1




1




New contributor




Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Badara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Ok, I see problem. Relation is invoked on instance of Query class and Query class cannot handle this relation. Try with ScCours::find()->join('mat')
    – Borisa Eric
    2 hours ago




















  • Ok, I see problem. Relation is invoked on instance of Query class and Query class cannot handle this relation. Try with ScCours::find()->join('mat')
    – Borisa Eric
    2 hours ago


















Ok, I see problem. Relation is invoked on instance of Query class and Query class cannot handle this relation. Try with ScCours::find()->join('mat')
– Borisa Eric
2 hours ago






Ok, I see problem. Relation is invoked on instance of Query class and Query class cannot handle this relation. Try with ScCours::find()->join('mat')
– Borisa Eric
2 hours ago












Badara is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Badara is a new contributor. Be nice, and check out our Code of Conduct.













Badara is a new contributor. Be nice, and check out our Code of Conduct.












Badara is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404609%2fyii2-syntax-error-or-access-violation-1066-not-unique-table%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

Alexandru Averescu

Trompette piccolo