Hi, I'm trying to do this looped insert update. It mostly works except that I keep getting an extra record - the last in the rss list. I'm thinking its because of my hasmany and belongs to declarations but its beyond me (at least for tonight!). Any expert tips?
Heres my controller function. function admin_load($id) { //get the feed url to read $this->Feed->read(null, $id); $feed_url = $this->Feed->data["Feed"]["feedurl"]; App::import('Vendor', 'testing', array('file'=>'magpie/rss_fetch.inc')); //get the feed and save the feed to the Feed model $f = fetch_rss($feed_url); $this->Feed->data["Feed"]['title'] = $f->channel['title']; $this->Feed->data["Feed"]['description'] = $f->channel['description']; $this->Feed->save(); //then loop thru each found feed. If findByLink finds something, update it, otherwise insert. foreach ($f->items as $item ) { if (! $this->Feed->FeedItem->findByLink($item["link"])){ $this->Feed->FeedItem->id = false; } if ($item["link"] == "") die('found'); $this->Feed->FeedItem->data["FeedItem"]["link"] = $item["link"]; $this->Feed->FeedItem->data["FeedItem"]["title"] = $item["title"]; $this->Feed->FeedItem->data["FeedItem"]["description"] = $item["description"]; $this->Feed->FeedItem->data["FeedItem"]["feed_id"] = $this->Feed->id; $this->Feed->FeedItem->save(); } } My Feed model <?php class Feed extends AppModel { var $name = 'Feed'; //The Associations below have been created with all possible keys, those that are not needed can be removed var $hasMany = array( 'FeedItem' => array('className' => 'FeedItem', 'foreignKey' => 'feed_id', 'dependent' => false, 'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'exclusive' => '', 'finderQuery' => '', 'counterQuery' => '' ) ); } ?> My FeedItem model <?php class FeedItem extends AppModel { var $name = 'FeedItem'; //The Associations below have been created with all possible keys, those that are not needed can be removed var $belongsTo = array( 'Feed' => array('className' => 'Feed', 'foreignKey' => 'feed_id', 'conditions' => '', 'fields' => '', 'order' => '' ) ); } ?> -- DRE http://www.increasetheknowledge.com http://www.theanticool.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---