milesj / uploader

[Deprecated] A CakePHP plugin for file uploading and validating.
MIT License
193 stars 73 forks source link

Delete hasmany associated #172

Closed hugofabricio closed 9 years ago

hugofabricio commented 10 years ago

Guys, my relacioanmentos are all ok, but when deleting a blog post, is also removed from the records blogsimages table, but the images are still in the directory anyone can give a force?

BlogsImage Model

/**
 * Configurações
 */
public $actsAs = array(
    'Uploader.Attachment' => array(
        'image' => array(
            'uploadDir' => 'img/blogs/',
            'overwrite' => true,
            'transforms' => array(
                'image' => array(
                    'nameCallback' => 'formatName',
                    'class' => 'crop',
                    'self' => true,
                    'width' => 480,
                    'height' => 320
                ),
                'image_small' => array(
                    'uploadDir' => 'img/blogs/thumbs/',
                    'append' => '-thumbs',
                    'nameCallback' => 'formatName',
                    'class' => 'crop',
                    'self' => false,
                    'width' => 180,
                    'height' => 180
                ),
                'image_medium' => array(
                    'uploadDir' => 'img/blogs/capa/',
                    'append' => '-capa',
                    'nameCallback' => 'formatName',
                    'class' => 'crop',
                    'self' => false,
                    'width' => 480,
                    'height' => 180
                )
            )
        )
    ),
    'Uploader.FileValidation' => array(
        'image' => array(
            'extension' => array('jpg', 'png', 'jpeg'),
            'required' => array(
                'value' => false,
                'allowEmpty' => true
            )
        )
    )
);

/**
 * Retorna o nome em formato slug
 */
public function formatName() {
    return $this->slugify($this->data['BlogsImage']['name_por']);
}

/**
 * Relacionamentos
 */
public $belongsTo = array(
    'Blog' => array(
        'className' => 'Blog',
        'foreignKey' => 'post_id'
    ),
    'Creator' => array(
        'className' => 'User',
        'foreignKey' => 'creator_id',
        'fields' => array('id', 'name')
    ),
    'Editor' => array(
        'className' => 'User',
        'foreignKey' => 'editor_id',
        'fields' => array('id', 'name')
    )
);

Blog Model

/**
 * Relacionamentos
 */
public $belongsTo = array(
    'BlogsCategory' => array(
        'className' => 'BlogsCategory',
        'foreignKey' => 'category_id'
    ),
    'Creator' => array(
        'className' => 'User',
        'foreignKey' => 'creator_id',
        'fields' => array('id', 'name')
    ),
    'Editor' => array(
        'className' => 'User',
        'foreignKey' => 'editor_id',
        'fields' => array('id', 'name')
    )
);

public $hasMany = array(
    'BlogsImage' => array(
        'className' => 'BlogsImage',
        'foreignKey' => 'post_id',
        'dependent' => true
    )
);
milesj commented 10 years ago

Using the latest versions correct?

I'm not sure if deleting a related model record will delete the images, as Cake callbacks might not be triggering. Will have to look into it.

hugofabricio commented 10 years ago

I`m use latest version

hugofabricio commented 10 years ago

I realized that it does not delete the image only when I'm using inside another plugin, for example I created the blog plugin, now if I pick up the controller model etc. Concerning the blog, and the image and the controls and templates folder, it deletes the related image .

milesj commented 10 years ago

Interesting, thanks for the info.

milesj commented 9 years ago

With CakePHP 3.0 just around the corner, and the fact that this project is deprecated, I will be closing this. If it's still an issue at some point, feel free to create a pull request.