I had the same problem here. My solution (definitely not a great one)
was to create a custom validation rule in app_model to prohibit
duplicate inserts (inserts with identical field values). Make sure to
set 'on' => 'create' in your rule array in $validation (of your
specific model) to make sure this only affects NEW saves and NOT
updates.
//---------------------------------------------------------------------------------------
function checkThatEntireEntryIsUnique($data,$ignoreFields=array()) {
//---------------------------------------------------------------------------------------
$valid = false;
$ignoreDefault = array('id');
$ignore = array_merge($ignoreDefault,$ignoreFields);
$passed_data = $this->data[$this->name];
foreach($ignore as $n => $v) {
if(isset($passed_data[$v])){
unset($passed_data[$v]);
}
}
$valid = $this->isUnique($passed_data, false);
return $valid;
}
On Jun 5, 9:07 am, Kyle Decot <[EMAIL PROTECTED]> wrote:
> I am trying to save a HABTM, but when i do a save, cake inserts 3
> rows. If you could please help me, I would be most grateful because I
> am under somewhat of a time constraint:
>
> teams_users
>
> team_id | user_id
> --------------------------------------
> 0 | 0
> 74 | 0
> 1 | 0
>
> 1 is my user_id and 74 is my team id. Here is my team_controller:
>
> function create() {
>
> $this->set("title","Create a New Team");
>
> if( !empty($this->data) ) {
>
> $success = false;
> $this->Team->create($this->data);
>
> if($this->Team->validates() &&
> ($this->Team->save(array("name"=>
> $this->data['Team']['name'],"captain_id"=>$this->Auth->user("id")))))
> {
>
> $team_id = $this->Team->getLastInsertId();
> $this->data['Team']['team_id'] = $team_id;
> $this->data['Team']['user_id'] =
> $this->Auth->user("id");
> $this->Team->User->save($this->data);
> $success = true;
>
> }
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---