2
votes

I am using CakePHP v.2.0 with MySQL.

I have two models, Candidate and Lottery connected with a HABTM relationship.

I want to make a save of this HABTM relation's data in my mysql db, with two restrictions:

1) I am not using a View, that is, i want to construct manually the data array passed as the first parameter in save function - but what's its format?

2) There is no candidates table, as my Candidate model loads data from LDAP (I’ve followed the tutorial at http://bakery.cakephp.org/articles/psychic/2009/03/12/ldap-models-in-cakephp). I just want to save in table lotteries and in the join table, candidates_lotteries.

Any ideas would be much appreciated.

1

1 Answers

1
votes

As long as your relationships are setup correctly in the models, and you do have the HABTM table, you can simply do the following:

$this->data['Candidate']['id'] = {CANDIDATE_ID};
$this->data['Lottery']['id'] = {LOTTERY_ID};
$this->Lottery->save($this->data);

This should show a new record in the HABTM table.