Tuesday, September 30, 2008

Finding records that have associated records

I'm a bit of a newbie when it comes to CakePHP and MySQL and I'm not
really sure about all of the terminology involved, so if this question
has been asked before, I apologize.

I have three models:

Skill
Tree
Link

A Skill hasAndBelongsToMany Links. A Skill hasMany Trees. Under
normal circumstances, a Skill should have at least 1 Link and 1 Tree.
But there are valid reasons that a Skill may have 0 Links and/or 0
Trees (e.g. when the Skill is a work-in-progress), but the casual end-
user of the site shouldn't really see these. Since there are
currently 707 Skills, I use Paginator to display them.

What I want to do is create some kind of Paginator query or condition
that will only display Skills that have 1 or more Links and 1 or more
Trees.

(I know I could probably do it easily using a tree_count and
link_count field in the skills table, but that'll be a lot of hassle
to set up. I was thinking there might be some better way to use, say,
a MySQL COUNT() function instead.)

Any thoughts? Thanks for your help!

Daniel

--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: