Sunday, July 29, 2012

CakePHP hasAndBelongsToMany relationships demystified

Hi everybody,

After days of trial-and-error and almost giving up, I've managed to get some basic and – as I believe – very common scenarios solved in CakePHP. I was wondering, why the documentation is not clear on these aspects, so I described my findings in a somewhat lengthy blog post.


I'm addressing a couple of questions:
  • Scenario where a User and a Group model share a bidirectional hasAndBelongsToMany relationship.
  • Saving a user with multiple groups.
  • Querying for a user who is a member of a specific group AND at the same time filtering on fields of the User model.
  • Adding additional groups for an existing user and keeping the join table up-to-date.
As I've read hundreds of questions somewhat related to this scenario on Stack Overflow, I assume there must be others out there, trying to wrap their heads around this.

I hope it helps.

Open for any conversation on Twitter, find me @ralf.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate