gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 04:50:25 26 4
gpt4 key购买 nike

我正在开发一个像“黄页”这样的网站,其数据库比我以前经历过的更复杂。

例如:该数据库有 3 个表:1. 组织——一些一般信息。2. 服务 - 包含可以提供的所有服务的列表。3.关系表。

组织表结构:

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

服务表结构:

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

等等你明白了

与关系表结构:

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

在网站输出中,我需要一个包含所有组织及其提供的所有服务的列表。

我不能完全理解(即使在阅读了 CookBook 中的将模型链接在一起部分之后)我应该如何使用 Cake 的语法和约定来组合所有这些表。

如果有人能向我提供 Cake 的模型/模型(我需要多少个?)示例并能够检索此数据,我将非常高兴。

最佳答案

我不能评论你的问题所以我会在这里问...

组织可以有很多服务,服务可以有很多组织吗?是HABTM关系吗? (只是检查...)

如果是,我将对其进行编辑并尝试为您提供答案。 :)

编辑:

表格

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)

模型

组织 - 在您的组织模型中,您必须拥有:

var $hasAndBelongsToMany = array('Service');

服务 - 在您的服务模型中,您必须具备:

var $hasAndBelongsToMany = array('Organisation');

仅此而已。其他一切都留给美丽的蛋糕。 :) 如果您不明白什么,请随时询问和here你可以获得更多信息。

关于php - CakePHP 需要有关组织模型的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12339782/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com