user195257
user195257

Reputation: 3316

CakePHP belongsTo relationship not saving

I have models 'PatientCase' and 'Procedure'. A case can have one/multiple procedures.

class PatientCase extends AppModel {
    public $hasMany = 'Procedure';
}

class Procedure extends AppModel {
    public $belongsTo = array(
            'PatientCase'       => array(
                'className'     => 'PatientCase'
            )
        );
}

I'm explicitly setting a value in my patientCasesController

$this->request->data["Procedure"]["side"] = 'left';

When i saveAll my patientCase, the case is saved correctly, and a new record is saved in the procedure table, with the corresponding patientCase id, however, no other data is saved in the record.

Can anyone see where i'm going wrong?

Upvotes: 0

Views: 826

Answers (1)

Dave
Dave

Reputation: 29121

Your comment nailed it - save() only saves the main model, while saveAll() saves the main model and any associated models.

save() [details]

saveAll() [details]

Update:

Because it's "hasMany", you probably want:

$this->request->data["Procedure"][0]["side"] = 'left';

(notice the [0])

Upvotes: 1

Related Questions