Wednesday, December 19, 2012

Testing model i have problem whit saveAssociated

Hi,

I have Models:
Profiles
    id
    name

ProfileTags
    id
    profile_id
    tag_id

Tags
    id
    name
-------------------------------------------------------------------------------------------------------
ProfileTest.php:
    public function testSaveCustomNew()
    {
        
        $data = array(
            'Profile' => array(
                'name' => 'New Profile 1'
            ),
            'ProfileTag' => array(
                array(
                    'tag_id' => '1'
                )
            )
        );

        $return = $this->Perfil->saveCustom($data);

        $this->assertEquals($return, 1);
      }
-------------------------------------------------------------------------------------------------------
Profile.php //Model
public $hasMany = array(
        'ProfileTag' => array(
            'className' => 'ProfileTag',
            'dependent' => true
        ),
    );
    public $hasAndBelongsToMany = array(
        'Tag' => array(
            'className' => 'Tag'
        )
    );
.
.
.
public function saveCustom($data)
    { 
        if (isset($data['id'])) {
            $data = Hash::insert($data, 'ProfileTag.{n}.profile_id', $data['id']);
        }

        if (empty($data['id'])) {
            $this->create();
        } else {
            $this->ProfileTag->deleteAll(array('profile_id' => $data['id']));
        }

        unset($this->ProfileTag->validate['profile_id']);

        $return = $this->saveAssociated($data);

        return $return;
    }
-------------------------------------------------------------------------------------------------------

The saveAssociated is getting PdoException. Does anybore knows the reason?

ps.: sorry about my poor english

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
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+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: