1

I have $hasAndBelongsToMany relation between projects and documents and they are linked with associative table projects_documents(id, project_id,document_id). Something likes that

class Projects extends AppModel {
    var $name = 'Projects';
    var $hasAndBelongsToMany = array(
        'Documents' => array(
            'className' => 'Documents',
            'joinTable' => 'projects_documents',
            'foreignKey' => 'project_id',
            'associationForeignKey' => 'document_id',
        ),
    );

It is working perfectly when updates and inserts are required. I’m required to add a flag field of each document of project. So I added a field in projects_documents, now table structure is id, project_id,document_id and flag. I know associated table updates by cake native function, that’s why it updates project_id and document_id by itself.

My question is how I can update the newly added field flag for each write operation. I’ve tried with manual queries but I want to implement this according to cake standards.

Thanks

Moyed Ansari
  • 8,436
  • 2
  • 36
  • 57
  • 1
    @MoyedAnsari remember that Model names are always singulars: *Project*, *Document*. Take a look to CakePHP Conventions: http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html – manzapanza Nov 19 '13 at 17:04
  • Thanks for highlighting @manzapanza – Moyed Ansari Nov 21 '13 at 06:07

0 Answers0