Database Structure for CakePHP Models
- by Michael T. Smith
We're building a data tracking web app using CakePHP, and I'm having some issues getting the database structure right. We have Companies that haveMany Sites. Sites haveMany DataSamples. Tags haveAndBelongToMany Sites.
That is all set up fine. The problem is "ranking" the sites within tags. We need to store it in the database as an archive. I created a Rank model that is setup like this:
rank (
id (int),
sample_id (int),
tag_id (int),
site_id (int),
rank (int),
total_rows)
)
So, the question is, how do I create the associations for tag, site and sample to rank? I originally set them as haveMany. But the returned structures don't get me where I'd like to be.
It looks like:
[Site] => Array (
[Sample] = Array(),
[Tag] = Array()
)
When I'm really looking for:
[Site] => Array (
[Tag] = Array (
[Sample] => Array (
[Rank] => Array (
...data...
)
)
)
)
I think that I may not be structuring the database properly; so if I need to update please let me know. Otherwise, how do I write a find query that gets me where I need to be? Thanks!
Thoughts? Need more details? Just ask!