Junction Table with mutiple primary keys

☆樱花仙子☆ 提交于 2019-12-11 14:03:34

问题


I started to learn Atk just a week ago and I decided to reimplement the business intranet which is becoming unmaintainable.

The model abstraction is very cool to use but I wonder how to specify multiple primary keys for my junction tables.

For example, I have sites and I want to assign machines on them for a period. Junction table

This is very important to me to not touch the database.


回答1:


I guess you can do that using joins in your Models if you're not allowed to add simple auto_incremented id field in that junction table.

But adding id field will be much more easier for you and also will work better in future.

For example, you can have some issues with deleting record without unique id field. I know (id_machine,id_site) is most likely unique in your case, but it's still hard to work with. One simple id field is easier, faster and better :)




回答2:


Dark has a good suggestion. You can also create a calculated ID field, I have never tried it myself but do try it

$model->getElement('id')->destroy();
$model->addExpression('id')->set('contact(id_machine,"-",id_site)');


来源:https://stackoverflow.com/questions/21281304/junction-table-with-mutiple-primary-keys

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!