Thanks, Reuben. I changed the $uses variable to 'FlagsInvoice' and it seems fine now! Didn't really want to explicitly define the FlagInvoice Model, as I really only need it in this one line of code.
Thanks for your help. On Friday, 16 May 2014 06:05:25 UTC+1, Reuben wrote: > > Since the convention would be for a join table to be flags_invoices > (alphabetical), the model name might be FlagsInvoice, even though CakePHP > to automagically generate a dynamic model of FlagInvoice while using the > HABTM relationship from the Flag or Invoice models. > > Though it might be easier to explicitly define the FlagInvoice model, as > per the example in hasMany through (The Join Model) ( > http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasmany-through-the-join-model > ) > > Regards > Reuben Helms > > On Friday, 16 May 2014 01:43:58 UTC+10, WhyNotSmile wrote: >> >> Ok, I'm probably being really dumb here, but I can't figure out how to >> delete an associated record when the association is HABTM. >> >> I have the following: >> >> *Invoice:* >> >> public $hasAndBelongsToMany = array( >> 'Flag' => array( >> 'counterCache' => true, >> ) >> ); >> >> I can add flags to invoices no problem (just by creating >> $invoice['Flag'][...] and then saving the invoice), but I can't figure out >> how to delete them! >> >> I've tried: >> $this->FlagInvoice->deleteAll( array( 'invoice_id' => $invoice_id, >> 'flag_id' => $flag_id ) ); >> and >> $this->FlagInvoice->deleteAll(); >> >> but I get "Call to a member function deleteAll() on a non-object" >> (presumably for the 'FlagInvoice'). >> >> If I add 'FlagInvoice' to the $uses variable at the top of the >> controller, I get the error that the table doesn't exist in the database. >> >> I know I'm missing something really obvious here (I'm pretty certain I've >> even done this before!), but I've looked online, and I can't find an >> answer. Can anyone help? Thanks! >> > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.