Bonjour,
J'ai une table 'artistes' et une table'promos'
Chaque artistes peut avoir plusieurs promos et chaque promos peut avoir plusieurs artistes donc j'ai créer une table 'artistes_promos'.
Dans la table 'promos' j'ai un champ 'media_id' et j'aimerais que ce champ ce remplisse dans la table de liaison 'artistes_promos'.
J'aimerais savoir si ses possibles et comment faire? sa fait x jour que j'essai mes je n'y arrive pas.
Voici mon debug de '$this->request->data' quand je sauvegarde une promo
les id de l'artiste et de la promo ce sauvegarde bien dans le table 'artistes_promos' mes pas le champ 'media_id'
Et aussi le champ id de la table 'artistes_promos' ce reincremente a chaque sauvegarde.
array(
'Promo' => array(
'name' => 'Soldiah Beez',
'content' => '<p>North Unity Sound</p>
',
'id' => '1',
'media_id' => '474',
'user_id' => '5',
'username' => 'sly'
),
'Artiste' => array(
'Artiste' => array(
(int) 0 => '21'
)
),
'ArtistesPromo' => array(
'Promo' => array(
'media_id' => '474'
)
)
)
La fonction admin_edit du PromosController
function admin_edit($id = null){
$this->Promo->contain('Artiste');
// On récupère l'article
if( $id ){
$promo = $this->Promo->find('first', array(
'conditions' => array('Promo.id' => $id),
'contain' => array('Thumb.file')
));
if(empty($promo)){
$this->Session->setFlash("OUPS!!! Ce lien n'éxiste pas!","flash");
return $this->redirect(array('action' => 'index'));
}
}
if(!empty($this->request->data)){
$this->request->data'Promo']'id'] = null;
if(isset($promo)){
$this->request->data'Promo']'id'] = $promo'Promo']'id'];
}
$this->request->data'Promo']'media_id'] = $promo'Promo']'media_id'];
$this->request->data'Promo']'user_id'] = $this->Auth->user('id');
$this->request->data'Promo']'username'] = $this->Auth->user('username');
$this->request->data'ArtistesPromo']'Promo']'media_id'] = $promo'Promo']'media_id'];
if($this->Promo->save($this->request->data)) {
return $this->redirect(array('action'=>'index'));
}
}else if($id){
$this->request->data = $promo;
$this->loadModel('ArtistesPromo');
$artistes = $this->request->data'Promo']'Promo'] = $this->ArtistesPromo->find('list', array (
'fields' => array ('artiste_id','artiste_id')
));
// retourne les artistes dans le selecteur
$artistes = $this->Promo->Artiste->find('list');
}
$this->set(compact('artistes','promo'));
}