Skip to content

Instantly share code, notes, and snippets.

@mariuswilms
Created February 1, 2009 15:54
Show Gist options
  • Select an option

  • Save mariuswilms/55888 to your computer and use it in GitHub Desktop.

Select an option

Save mariuswilms/55888 to your computer and use it in GitHub Desktop.
<?php
class Movie extends AppModel {
// ...
var $hasMany = array(
'Attachment' => array(
'className' => 'Media.Attachment',
'foreignKey' => 'foreign_key',
'conditions' => array('Attachment.model' => 'Movie'),
'dependent' => true,
));
// ...
}
?>
<?php
class MoviesController extends AppController {
function edit($id = null) {
// ...
// $this->data = array(
// 'Movie' => array('id' => $id, 'title' => 'Vicky Cristina Barcelona'),
// 'Attachment' => array(
// 0 => array('file' => transferable item1, 'model' => 'Movie'),
// 1 => array('file' => transferable item2, 'model' => 'Movie'),
// ));
$this->Movie->saveAll($this->data, array('validate' => 'first'));
// ...
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment