Junction Table with mutiple primary keys

2019-09-09 16:10发布

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.

标签: atk4
2条回答
ら.Afraid
2楼-- · 2019-09-09 16:30

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)');
查看更多
Ridiculous、
3楼-- · 2019-09-09 16:43

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 :)

查看更多
登录 后发表回答