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

Multi tool use
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!
yii2
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.
add a comment |
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!
yii2
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 * FROMsc_cours
a
INNER JOINsc_matieres
b
ON a.idMat = b.idMat INNER JOINsc_matieres
b
ON a.idMat = b.idMat
– Badara
yesterday
add a comment |
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!
yii2
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
yii2
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.
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 * FROMsc_cours
a
INNER JOINsc_matieres
b
ON a.idMat = b.idMat INNER JOINsc_matieres
b
ON a.idMat = b.idMat
– Badara
yesterday
add a comment |
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 * FROMsc_cours
a
INNER JOINsc_matieres
b
ON a.idMat = b.idMat INNER JOINsc_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
add a comment |
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');
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 * FROMsc_cours
a
INNER JOINclasse
– Badara
yesterday
whyclasse
if your relation name isgetMat()
then your relation should bemat
and it would take from tabel defined inScMatieres
– Borisa Eric
18 hours ago
sorry it's me who do an error here (it just because i do the same with another tablessc_classes
, sorry for that again ...) but unfortunately even if i writemat
, i get the same error, telling me thatthe 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
add a comment |
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...
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 withScCours::find()->join('mat')
– Borisa Eric
2 hours ago
add a comment |
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');
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 * FROMsc_cours
a
INNER JOINclasse
– Badara
yesterday
whyclasse
if your relation name isgetMat()
then your relation should bemat
and it would take from tabel defined inScMatieres
– Borisa Eric
18 hours ago
sorry it's me who do an error here (it just because i do the same with another tablessc_classes
, sorry for that again ...) but unfortunately even if i writemat
, i get the same error, telling me thatthe 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
add a comment |
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');
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 * FROMsc_cours
a
INNER JOINclasse
– Badara
yesterday
whyclasse
if your relation name isgetMat()
then your relation should bemat
and it would take from tabel defined inScMatieres
– Borisa Eric
18 hours ago
sorry it's me who do an error here (it just because i do the same with another tablessc_classes
, sorry for that again ...) but unfortunately even if i writemat
, i get the same error, telling me thatthe 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
add a comment |
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');
From error you can see that you have two inner joins exact same. Define relation in model and than just do ->innerJoin('nameOfRelation');
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 * FROMsc_cours
a
INNER JOINclasse
– Badara
yesterday
whyclasse
if your relation name isgetMat()
then your relation should bemat
and it would take from tabel defined inScMatieres
– Borisa Eric
18 hours ago
sorry it's me who do an error here (it just because i do the same with another tablessc_classes
, sorry for that again ...) but unfortunately even if i writemat
, i get the same error, telling me thatthe 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
add a comment |
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 * FROMsc_cours
a
INNER JOINclasse
– Badara
yesterday
whyclasse
if your relation name isgetMat()
then your relation should bemat
and it would take from tabel defined inScMatieres
– Borisa Eric
18 hours ago
sorry it's me who do an error here (it just because i do the same with another tablessc_classes
, sorry for that again ...) but unfortunately even if i writemat
, i get the same error, telling me thatthe 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
add a comment |
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...
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 withScCours::find()->join('mat')
– Borisa Eric
2 hours ago
add a comment |
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...
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 withScCours::find()->join('mat')
– Borisa Eric
2 hours ago
add a comment |
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...
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';
}
}
}
}
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.
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 withScCours::find()->join('mat')
– Borisa Eric
2 hours ago
add a comment |
Ok, I see problem. Relation is invoked on instance of Query class and Query class cannot handle this relation. Try withScCours::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
add a comment |
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.
Badara is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Ip6A8mQgGhcMnEY Yb,UX8KZ2vEEY FxVjyuIfBBW 986vW4RTYfa6AMw6U0Tvrm,8GowL6PIuEMhbsE0A,9wNbdY UwHzSfgRfL1,6sq
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 JOINsc_matieres
b
ON a.idMat = b.idMat INNER JOINsc_matieres
b
ON a.idMat = b.idMat– Badara
yesterday