Skip to content

Commit

Permalink
Merge pull request #36 from krolow/develop
Browse files Browse the repository at this point in the history
Merge develop changes
  • Loading branch information
krolow committed Nov 21, 2014
2 parents b20ea2b + 9ea71c2 commit 3638634
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
90 changes: 90 additions & 0 deletions Config/Migration/1384466065_create_attachments_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
class CreateAttachmentsTable extends CakeMigration {

/**
* Migration description
*
* @var string
* @access public
*/
public $description = '';

/**
* Actions to be performed
*
* @var array $migration
* @access public
*/
public $migration = array(
'up' => array(
'create_table' => array(
'attachments' => array(
'id' => array(
'type' => 'integer',
'null' => false,
'default' => null,
'key' => 'primary'
),
'filename' => array(
'type' => 'string',
'null' => false,
'length' => 150
),
'model' => array(
'type' => 'string',
'null' => false,
'length' => 150
),
'foreign_key' => array(
'type' => 'integer',
'null' => false
),
'type' => array(
'type' => 'string',
'null' => false,
'length' => 100
),
'indexes' => array(
'PRIMARY' => array(
'column' => 'id',
'unique' => 1
),
),
'tableParameters' => array(
'charset' => 'latin1',
'collate' => 'latin1_swedish_ci',
'engine' => 'InnoDB'
),
),
),
),
'down' => array(
'drop_table' => array(
'attachments'
),
),
);


/**
* Before migration callback
*
* @param string $direction, up or down direction of migration process
* @return boolean Should process continue
* @access public
*/
public function before($direction) {
return true;
}

/**
* After migration callback
*
* @param string $direction, up or down direction of migration process
* @return boolean Should process continue
* @access public
*/
public function after($direction) {
return true;
}
}
3 changes: 2 additions & 1 deletion Model/Behavior/UploadBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ public function setup(Model $model, $config = array()) {
* @return void
*/
protected function _setRelationModel(Model $model, $type) {
$type = Inflector::camelize($type);
$relation = 'hasOne';

//case is defined multiple is a hasMany
if ($this->isMultiple($model, $type)) {
$relation = 'hasMany';
}

$type = Inflector::camelize($type);

$model->{$relation}['Attachment' . $type] = array(
'className' => 'Attachment',
'foreignKey' => 'foreign_key',
Expand Down

0 comments on commit 3638634

Please sign in to comment.