douren9077 2012-09-09 14:09
浏览 10
已采纳

CakePHP需要有关组织模型的建议

I'm developing a site like "yellow pages" with more complex DB than I had ever experienced before.

For example: This DB has 3 tables: 1. organisations – with some general information. 2. services - with list of all services that can be provided. 3. relation table.

Organisations table structure:

id    name         city       phone      etc.
1     CompanyName  Farewell   987-65-43

Services table structure:

id    ServiceType  
1     purchase  
-----
2     sale  
-----
3     exchange 

etc.. you get the point

And relation table structure:

id    OrganisationID   ServId      
1     1                2
----
2     1                3
----   
3     1                6
----
4     2                3

In website output I need a list of all organisations with all the services they provide.

I can't fully understand (even after reading Linking Models Together section in the CookBook) how I should combine all this tables using Cake's syntax and conventions.

I'll be glad if anyone can provide me a Cake's model/model's (how many I need?) example with ability to retrieve this data.

  • 写回答

1条回答 默认 最新

  • dongyo7931 2012-09-09 14:47
    关注

    I can't comment on your question so I'll ask here...

    Organisations can have many services and services can have many organisations? Is it HABTM relationship? (Just checking...)

    If it is, I'll then edit this and try to give you the answer. :)

    EDIT:

    TABLES

    1. table: organisations
    2. table: services
    3. table: organisations_services (sorted alphabetically)
    
    
    1. table: id, name, city...
    2. table: id, service_type
    3. table: id, organisation_id, service_id (singular, sorted alphabetically)
    

    MODELS

    Organisation - inside your organisation model you must have:

    var $hasAndBelongsToMany = array('Service');
    

    Service - inside your service model you must have:

    var $hasAndBelongsToMany = array('Organisation');
    

    And that's all. Everything else leave to the beautiful Cake. :) If you don't understand something, feel free to ask and here you can get more information.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路