EDIT:
Some news.. i've deatached the polymorphic behaviour and the problem
continues...

What can be? that $this->file = $this->find($this->id); inside before save
sometimes returns the same id for Banner and Icon:

class Picture extends AppModel {
    var $name = 'Picture';

    function beforeDelete() {
        $this->file = $this->read(null, $this->id);
        return true;
    }

    function afterDelete()     {
        foreach($this->file as $file):
            unlink('files'.DS.$file['path']);
        endforeach;

        return true;
    }

    function beforeSave() { //for edit(update)
        if($this->id) {
            $this->file = $this->find($this->id);
        }
        return true;
    }

    function afterSave() { //for edit(update)

        if(!empty($this->file)) {
            foreach($this->file as $file):
                unlink('files'.DS.$file['path']);
            endforeach;
        }
        return true;
    }
}


Line model:
<?php
class Line extends AppModel {
    var $name = 'Line';
    var $displayField = 'name';
    var $actsAs = array('Sluggable' => array('separator' => '-', 'overwrite'
=> true, 'label' => 'name','translation' => 'utf-8'));
    //The Associations below have been created with all possible keys, those
that are not needed can be removed

    var $hasMany = array(
        'Family' => array(
            'className' => 'Family',
            'foreignKey' => 'line_id',
            'dependent' => false,
        )
    );
    var $hasOne = array(
        'Banner' => array(
            'className' => 'Picture',
            'foreignKey' => 'foreign_id',
            'conditions' => array('Banner.class' => 'Line', 'Banner.type' =>
'banner'),
            'dependent' => true,
        ),
        'Icon' => array(
            'className' => 'Picture',
            'foreignKey' => 'foreign_id',
            'conditions' => array('Icon.class' => 'Line', 'Icon.type' =>
'icon'),
            'dependent' => true,
        ),
    );
}
?>


Att,

Henrique Machado
TI Expert


2010/9/15 Henrique Machado <henri....@gmail.com>

> Please somebody can help with it? I've provided all scenario, something
> wrong with my question?
>
>
>
> Att,
>
> Henrique Machado
> TI Expert
>
>
> 2010/9/15 Henrique Machado <henri....@gmail.com>
>
> Hello everybody!
>>
>> After a whole day trying to make my application work correctly, asking for
>> help on IRC and some friends, I concluded that I found a bug in polymorphic
>> Behaviour.
>>
>> My Scenario:
>>
>> The Picture is my Polymorphic Model:
>> Picture model: http://bin.cakephp.org/view/1085677267
>>
>> Family hasOne Banner (Banner is an alias to Picture that is polymorphic)
>> Family hasOne icon (Icon is an alias to Picture that is polymorphic)
>> Family model: http://bin.cakephp.org/view/2133641829
>> Family controller: http://bin.cakephp.org/view/827099383
>> Family add_view: http://bin.cakephp.org/view/478488471
>> Family edit_view: http://bin.cakephp.org/view/751543170
>>
>> When I add a Family I Can add a Banner or Icon or Both relationed too. This
>> is working great, the picture is uploaded and the records are saved in the
>> pictures table.
>>
>> When I delete a Family, the Banner or the Icon or Both Should be deleted
>> from table (Pictures) and files Should Be unliked. This is working great
>> too.
>>
>> The problem is when I'm editing Family. I tried many ways to get it
>> working with find(), read() at BeforeSave () afterSave(), but i can not get
>> it.
>>
>> This is the debug on beforeSave (When Works)
>> http://bin.cakephp.org/view/2145699735
>>
>> This is the debug on beforeSave (When Bug)
>> http://bin.cakephp.org/view/135653162
>>
>> Please Note that when it fail, the ID is THE SAME for both (here is the
>> bug) Banner and Icon, array looks mixed up (both Have type => icon)
>>
>> Sometimes, the Behaviour Appears to be mixing arrays when updating both
>> (Icon and Banner) .. But sometimes work.. looks random.
>>
>> It's the Behaviour? Or I'm missing something?
>>
>> Thanks in advance
>>
>>
>> Att,
>>
>> Henrique Machado
>> TI Expert
>>
>
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to