doukucai0099 2014-12-19 15:57
浏览 62
已采纳

一般CakePHP:hasMany toAndBelongsToMany

I’ve been handed a web site, written in CakePHP to modify, and I am loving it! The theme and documentation are wonderful; and I love how organized the code is.

My task is to modify a database relationship, between two tables, from being one-to-many to a many-to-many; or in cake terms from a “hasMany” to a “hasAndBelongsToMany”.

I created the new intermediary table (in the MySql database) for the many-to-many relationship, but I’m trying to figure out where to go from there.

Should I run bake now that the table is created? Would that be the best next step?

What’s the best method to find out each of the files I’ll need to change the code in? I’ve used Notepad++ and have done a Search->Find In Files… to look for the name of one of the tables in the relationship, within the code. But with the data being organized into MVC, I think there must be a better way to identify all the areas where the code I need to modify is. I know each table has a view, controller and a model. Are those three places all inclusive; or are there other files and folders I should look into too?

(I’m somewhat new to the MVC design pattern in PHP. I understand the concept; but I’m used to having PHP and HTML all in one file, and being able to see a visual in DW. So having the code organized in MVC with no visual, has been quite the learning curve for me. )

Thanks so much.

  • 写回答

1条回答 默认 最新

  • dongxi1943 2014-12-19 18:27
    关注

    Running bake is probably not a good idea for an already running application.

    This won't be a simple task unless you have a very straight forward application at least regarding those tables. First you need to identify the functional changes even before touching code. To do that you need a good understanding of the already underlying logic.

    You should start with the two models involved. Are there custom finds and logic that will need to change? Then go to the controllers and ask the same. Decide if you'll need a model for the intermediate model. Try to understand the impact of the changes for the rest of the app. If you correctly identify these then it'll be easy to adapt them to the change.

    Unfortunately your milage may vary depending on the complexity of the code.

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

报告相同问题?

悬赏问题

  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决