Re: Recursive delete not working
I figured it out. For the recursive delete to work, you have to set the second parameter of bindModel to true, which makes the binding still until the end of the request. Otherwise it only sticks for the next Model operation and then reverts back to not existing before it gets a chance to do the other recursive delete Model operations. Here's my revised controller code: $this->Account->bindModel( array('hasMany' => array( 'Update' => array('dependent' => true, 'exclusive' => true), 'Feed' => array('dependent' => true, 'exclusive' => true) ), true )); $this->Account->delete($id); - Jason On May 11, 3:52 pm, Jason wrote: > Wow - so I feel dumb about that mistake! I updated my code and it is > working now. I was going crazy trying to figure that out! > > Now I'm having an issue where bindings that are established in the > model are recursively deleting, but bindings I set on the fly in the > controller are not deleting. Here's the code from my controller: > > $this->Account->bindModel(array('hasMany' => array( > 'Update' => array('dependent' => true, 'exclusive' => > true), > 'Feed' => array('dependent' => true, 'exclusive' => > true) > ))); > $this->Account->delete($id); > > The Searchfeed, Author, and Rule models are recursively deleting based > on my model code from above (with the spelling error fixed) but the > Update and Feed models are not deleting. > > Is there some trick for getting on-the-fly bindings to work > withrecursivedeletion? > > Thanks! > - Jason > > On May 11, 3:00 am, schneimi wrote: > > > Hi, > > > just a misspelling, try 'dependent' instead of 'dependant' ;-) > > > Michael > > > Jason schrieb: > > > > I can't figure out what I'm doing wrong here. I'm fairly new to > > > CakePHP and have been having a lot of success getting a new app set > > > up, but I'm running up against a brick wall trying to getrecursive > > >deleteworking. > > > > Here is my Account model: > > > > class Account extends AppModel { > > > var $hasMany = array( > > > 'Searchfeed' => array( > > > 'order' => 'Searchfeed.created DESC', > > > 'dependant' => true, > > > 'exclusive' => true > > > ), > > > 'Author' => array( > > > 'order' => 'Author.created DESC', > > > 'dependant' => true, > > > 'exclusive' => true > > > ), > > > 'Rule' => array( > > > 'order' => 'Rule.created DESC', > > > 'dependant' => true, > > > 'exclusive' => true > > > ), > > > ); > > > } > > > > I am running this in the controller: > > > > $this->Account->del($id); > > > > Cake generates SQL todeletefrom the accounts table, but it does not > > > even attempt to touch the other tables that are dependent. I even > > > tried forcing the $cascade variable (which default to true) like this: > > > > $this->Account->del($id, true); > > > > But I get the same result. It only deletes from the primary model, not > > > from the dependent models. What am I doing wrong? > > > > - Jason --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Recursive delete not working
Wow - so I feel dumb about that mistake! I updated my code and it is working now. I was going crazy trying to figure that out! Now I'm having an issue where bindings that are established in the model are recursively deleting, but bindings I set on the fly in the controller are not deleting. Here's the code from my controller: $this->Account->bindModel(array('hasMany' => array( 'Update' => array('dependent' => true, 'exclusive' => true), 'Feed' => array('dependent' => true, 'exclusive' => true) ))); $this->Account->delete($id); The Searchfeed, Author, and Rule models are recursively deleting based on my model code from above (with the spelling error fixed) but the Update and Feed models are not deleting. Is there some trick for getting on-the-fly bindings to work with recursive deletion? Thanks! - Jason On May 11, 3:00 am, schneimi wrote: > Hi, > > just a misspelling, try 'dependent' instead of 'dependant' ;-) > > Michael > > Jason schrieb: > > > I can't figure out what I'm doing wrong here. I'm fairly new to > > CakePHP and have been having a lot of success getting a new app set > > up, but I'm running up against a brick wall trying to getrecursive > >deleteworking. > > > Here is my Account model: > > > class Account extends AppModel { > > var $hasMany = array( > > 'Searchfeed' => array( > > 'order' => 'Searchfeed.created DESC', > > 'dependant' => true, > > 'exclusive' => true > > ), > > 'Author' => array( > > 'order' => 'Author.created DESC', > > 'dependant' => true, > > 'exclusive' => true > > ), > > 'Rule' => array( > > 'order' => 'Rule.created DESC', > > 'dependant' => true, > > 'exclusive' => true > > ), > > ); > > } > > > I am running this in the controller: > > > $this->Account->del($id); > > > Cake generates SQL todeletefrom the accounts table, but it does not > > even attempt to touch the other tables that are dependent. I even > > tried forcing the $cascade variable (which default to true) like this: > > > $this->Account->del($id, true); > > > But I get the same result. It only deletes from the primary model, not > > from the dependent models. What am I doing wrong? > > > - Jason --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Recursive delete not working
Hi, just a misspelling, try 'dependent' instead of 'dependant' ;-) Michael Jason schrieb: > I can't figure out what I'm doing wrong here. I'm fairly new to > CakePHP and have been having a lot of success getting a new app set > up, but I'm running up against a brick wall trying to get recursive > delete working. > > Here is my Account model: > > class Account extends AppModel { > var $hasMany = array( > 'Searchfeed' => array( > 'order' => 'Searchfeed.created DESC', > 'dependant' => true, > 'exclusive' => true > ), > 'Author' => array( > 'order' => 'Author.created DESC', > 'dependant' => true, > 'exclusive' => true > ), > 'Rule' => array( > 'order' => 'Rule.created DESC', > 'dependant' => true, > 'exclusive' => true > ), > ); > } > > I am running this in the controller: > > $this->Account->del($id); > > Cake generates SQL to delete from the accounts table, but it does not > even attempt to touch the other tables that are dependent. I even > tried forcing the $cascade variable (which default to true) like this: > > $this->Account->del($id, true); > > But I get the same result. It only deletes from the primary model, not > from the dependent models. What am I doing wrong? > > - Jason --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Recursive delete not working
I can't figure out what I'm doing wrong here. I'm fairly new to CakePHP and have been having a lot of success getting a new app set up, but I'm running up against a brick wall trying to get recursive delete working. Here is my Account model: class Account extends AppModel { var $hasMany = array( 'Searchfeed' => array( 'order' => 'Searchfeed.created DESC', 'dependant' => true, 'exclusive' => true ), 'Author' => array( 'order' => 'Author.created DESC', 'dependant' => true, 'exclusive' => true ), 'Rule' => array( 'order' => 'Rule.created DESC', 'dependant' => true, 'exclusive' => true ), ); } I am running this in the controller: $this->Account->del($id); Cake generates SQL to delete from the accounts table, but it does not even attempt to touch the other tables that are dependent. I even tried forcing the $cascade variable (which default to true) like this: $this->Account->del($id, true); But I get the same result. It only deletes from the primary model, not from the dependent models. What am I doing wrong? - Jason --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---