Skip to content
Snippets Groups Projects
Commit a938ad3d authored by SASSU Thomas's avatar SASSU Thomas
Browse files

bug association not fixed

parent 98531732
No related branches found
No related tags found
No related merge requests found
<?php <?php
require_once __DIR__ . '../vendor/autoload.php'; require_once dirname (__DIR__) . '../vendor/autoload.php';
session_start();
use \Slim\Slim as Slim; use \Slim\Slim as Slim;
use Illuminate\Database\Capsule\Manager as DB; use Illuminate\Database\Capsule\Manager as DB;
......
...@@ -82,9 +82,40 @@ class ControleurScript ...@@ -82,9 +82,40 @@ class ControleurScript
echo ("<p>---------------------------------------------<br>" . echo ("<p>---------------------------------------------<br>" .
"<p>(name, deck) des personnages du jeu 12342<br>" . "<p>(name, deck) des personnages du jeu 12342<br>" .
"<p>---------------------------------------------<br>"); "<p>---------------------------------------------<br>");
foreach ($q1 as $item) { foreach ($q1 as $item) {
echo "<p>nom :$q1->name , deck : $q1->deck</p>"; echo "<p>nom :$item->name , deck : $item->deck</p>";
}
$q2 = Game::where('name','like',"Mario%")->get();
echo ("<p>---------------------------------------------<br>" .
"<p>les personnages des jeux dont le nom (du jeu) débute par 'Mario<br>" .
"<p>---------------------------------------------<br>");
foreach ($q2 as $game) {
echo "<p>Characters from :$game->name</p>";
$list = $game->characters()->get();
foreach ($list as $char)
echo "<p>nom : $char->name</p>";
}
$q3 = Company::where("name", "like", "%sony%")->get();
echo ("<p>---------------------------------------------<br>" .
"<p>les jeux développés par une compagnie dont le nom contient 'Sony<br>" .
"<p>---------------------------------------------<br>");
foreach ($q3 as $company) {
echo "<p>Games from :$company->name</p>";
$list = $company->games()->get();
foreach ($list as $game)
echo "<p>nom : $game->name</p>";
}
$q2 = Game::where('name','like',"%Mario%")->get();
echo ("<p>---------------------------------------------<br>" .
"<p>le rating initial (indiquer le rating board) des jeux dont le nom contient Mario<br>" .
"<p>---------------------------------------------<br>");
foreach ($q2 as $game) {
$list = $game->ratings()->get();
foreach ($list as $rate)
echo "<p>id rating_board : $rate->rating_board_id, name : {$rate->rating_boards()->first()->name}</p>";
} }
} }
......
...@@ -7,6 +7,6 @@ class Company extends \Illuminate\Database\Eloquent\Model ...@@ -7,6 +7,6 @@ class Company extends \Illuminate\Database\Eloquent\Model
public $timestamps = false; public $timestamps = false;
function games(){ function games(){
return $this->BelongsToMany('gp\modeles\Game', 'game2company','company_id'); return $this->BelongsToMany('gp\modeles\Game', 'game_developers','comp_id');
} }
} }
...@@ -10,17 +10,17 @@ class Game extends \Illuminate\Database\Eloquent\Model ...@@ -10,17 +10,17 @@ class Game extends \Illuminate\Database\Eloquent\Model
public function characters(){ public function characters(){
return $this->belongsToMany('gp\modeles\Character', 'game2character','game_id'); return $this->belongsToMany('gp\modeles\Character', 'game2character','game_id');
} }
public function platform(){ public function platforms(){
return $this->belongsToMany('gp\modeles\Platform', 'game2platform','game_id'); return $this->belongsToMany('gp\modeles\Platform', 'game2platform','game_id');
} }
public function theme(){ public function themes(){
return $this->belongsToMany('gp\modeles\Theme', 'game2theme','game_id'); return $this->belongsToMany('gp\modeles\Theme', 'game2theme','game_id');
} }
public function genre(){ public function genres(){
return $this->belongsToMany('gp\modeles\Genre', 'game2genre','game_id'); return $this->belongsToMany('gp\modeles\Genre', 'game2genre','game_id');
} }
public function rating(){ public function ratings(){
return $this->belongsToMany('gp\modeles\Rating', 'game2rating','game_id'); return $this->belongsToMany('gp\modeles\Game_rating', 'game2rating','game_id');
} }
public function publishers(){ public function publishers(){
return $this->belongsToMany('gp\modeles\Company', 'game_publishers','game_id'); return $this->belongsToMany('gp\modeles\Company', 'game_publishers','game_id');
......
...@@ -3,14 +3,53 @@ namespace gp\modeles; ...@@ -3,14 +3,53 @@ namespace gp\modeles;
class Game_rating extends \Illuminate\Database\Eloquent\Model class Game_rating extends \Illuminate\Database\Eloquent\Model
{ {
protected $table = 'game_rating'; protected $table = 'game_rating';
protected $primaryKey ='id'; protected $primaryKey =['id', 'rating_id'];
public $timestamps = false; public $timestamps = false;
public $incrementing = false;
function games(){ function games(){
return $this->BelongsToMany('gp\modeles\Game', 'game2rating','rating_id'); return $this->BelongsToMany('gp\modeles\Game', 'game2rating','rating_id');
} }
function rating_board(){ function rating_board(){
return $this->BelongsTo('gp\modeles\Rating_board', 'id'); return $this->BelongsTo('gp\modeles\Rating_board', 'rating_board_id');
}
/**
* Set the keys for a save update query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function setKeysForSaveQuery(Builder $query)
{
$keys = $this->getKeyName();
if(!is_array($keys)){
return parent::setKeysForSaveQuery($query);
}
foreach($keys as $keyName){
$query->where($keyName, '=', $this->getKeyForSaveQuery($keyName));
}
return $query;
}
/**
* Get the primary key value for a save query.
*
* @param mixed $keyName
* @return mixed
*/
protected function getKeyForSaveQuery($keyName = null)
{
if(is_null($keyName)){
$keyName = $this->getKeyName();
}
if (isset($this->original[$keyName])) {
return $this->original[$keyName];
}
return $this->getAttribute($keyName);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment