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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器