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.
You might find this helpful: http://www.24100.net/2012/07/cakephp-hasandbelongstomany-relationship-queries-demystified/.
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.
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