9

Database structure for CakePHP models

 3 years ago
source link: https://www.codesd.com/item/database-structure-for-cakephp-models.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Database structure for CakePHP models

advertisements

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!


According to the data format you want,I suggest you changing sites haveMany samples to tags hasMany samples.And make sure you have bulit the table which is

samples_tags (
id (int),
sample_id (int),
tag_id (int)
)

And also check you have defined the models' association correctly.More detail please see HABTM in cookbook.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK