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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度