Tags
Recent Comments
Elsewhere
Bookmarked 9 links
Free DNS service - Easy, web-based domain manager - ZoneEdit.com
Zerigo Managed DNS Hosting with an API | Zerigo
EditDNS - US and Europe DNS Hosting
FreeDNS - Free DNS - Dynamic DNS - Static DNS subdomain and domain hosting
Spicers Clovelly Estate | Spicers Clovelly Estate
Bookmarked 9 links
Dessine moi un objet » Blog Archive » Iphone and Itouch paper stand / dock
Waveboard – Google Wave Client for iPhone and Mac
Livestream - Broadcast LIVE streaming video
The LinkedIn Blog » Blog Archive LinkedIn: 50 million professionals worldwide «
Find the Best Twitter Apps for the iPhone, Blackberry, Web & More - oneforty
Updated status: On iPhone with IM+
Bookmarked 10 links
Home - Mixpanel | Real-time Web Analytics, Funnel Analysis
Social Media Monitoring Tools & Reputation Tracking | Trackur
Radian6 - Social Media Monitoring, Measurement and Engagement
Trendsmap - Real-time local Twitter trends
Tweetboard - True Twitter Conversation
Appointment Software Plus Contact Widget - Setster
Beautiful Soup: We called him Tortoise because he taught us.
Links
Working with Associations using CakePHP
I was asked by Niraja Mulye of Packt Publishing if I would be interested in publishing an article on my blog from the book, CakePHP Application Development. Since it seems relevant to any starting out with CakePHP, I guess why not.
Instead of copying and pasting what was sent, I found two articles which seemed like the original source. Being properly formatted, I guess it will be more appropriate for me to point them to you. The first article titled, Working with Simple Associations using CakePHP talks about the basic belongsTo, hasOne and hasMany assocations while the second article titled, Working with Complex Associations using CakePHP tackles the hasAndBelongsToMany association where most beginners have difficulty with.
The articles will be useful for anyone starting out but unfortunately, CakePHP had gone through lots of changes and the book (published on July 2008) is based on an older version of CakePHP. So now there are actually better ways of dealing with associations using the Containable Behavior. The Containable Behavior binds and unbinds model on the fly, automatically setting the recursive level to suit. This means you no longer have to bother about setting the recursive level as long as you “contain” your
find()queries. I am mentioning this because I have to warn against the setting of recursive level directly.// All models have recursive level set to 1 by default $this->Author->recursive = 2; $this->Author->id = 1001; $this->Author->find('first'); // Return results based on recursive level of 2 // some // codes // in // between $this->Author->find('all'); // Return results based on recursive level of 2 (as set previously) and not 1!This causes CakePHP to retrieve more data than it should when it is unintended by you. My suggestion is to have all models default to recursive level -1 by setting it in the AppModel and let “contain” handle the rest.
$this->Author->id = 1001; $this->Author->find('first', array('contain' => 'Book')); // Returns author 1001 and all books authored by him/her $this->Author->find('all'); // Returns all authors onlyHow nice!