1
votes

I have a Model User:

public $hasMany = array(
    'Contact' => array('dependent' => true));
public $hasAndBelongsToMany = array(
    'MySharepermission' => array(
        'unigue' => false,
        'className' => 'Contact',
        'joinTable' => 'sharepermissions_users',
        ));

And a Model Contact

public $belongsTo = array('User');    
public $hasAndBelongsToMany = array(
    'Sharepermission' => array(
        'unigue' => false,
        'className' => 'User',
        'joinTable' => 'sharepermissions_users',
        )
    );

Now i have an array of $data:

array(
(int) 0 => array(
    'Contact' => array(
        'id' => '51254509-0654-468b-8007-1683550d8ff8'
    ),
    'Sharepermission' => array(
        'id' => '5123a3c3-d5ac-4541-b28b-326c550d8ff8',
        'permission' => 'read'
    )
),
(int) 1 => array(
    'Contact' => array(
        'id' => '51254509-0654-468b-8007-1683550d8ff8'
    ),
    'Sharepermission' => array(
        'id' => '51252eba-8804-40e7-bf3d-7db9550d8ff8',
        'permission' => 'write'
    )
)
)

The Database is currently Empty and now i do:

debug($this->Contact->saveAll($data));

The result is quite odd: enter image description here

Why is that so?

2
That is odd, one thing you should definitely do is change the mysql data type of the foriegn keys (*_id) to CHAR(32) if you're using UUIDs - Dunhamzzz
i have been using binary(36) for uuid for a long time, it works like a charm - Alex Schneider
fair, I was just suggesting because clearly the 0000s aren't a UUID - Dunhamzzz
yes, but the data type is no problem. something is mssed up with the saving. even the record in the first line is corrupted. it should have 'write' permission - Alex Schneider
Probably not causing your problem, but in your example there's a key 'unigue' (with a g in stead of a q) in your HABTM definitions - thaJeztah

2 Answers

0
votes

How does your Sharepermisson Model look like?

It seems you have an error in your Contact-habtm relation:

public $hasAndBelongsToMany = array(
    'MySharepermission' => array(
        'unigue' => false,
        'className' => 'Contact',
        'joinTable' => 'sharepermissions_cantacts',
        ));

Have you tried to only save the Contact-part without the User relation?

0
votes

I see that the word unique is misspelled it should be "unique" not "unigue". It might solve the case.