简体   繁体   English

10月CMS的pivot表中多次添加同一个链接

[英]Add the same link multiple times in the pivot table in October CMS

I have two tables, having many-to-many relationship between them (user, shop) and a pivot table (visit) that links them together:我有两个表,它们之间具有多对多关系(用户、商店)和一个将它们链接在一起的 pivot 表(访问):

table user {
    id,
    name
}

table shop {
    id,
    name
}

table visit {
    id,
    user_id,
    shop_id,
    date
}

On the user's backend page, I'd like to be able to add multiple visits to the same shop.在用户的后端页面上,我希望能够添加对同一家商店的多次访问。 I use relation config, and a table is displayed, having an "Add" button on top.我使用关系配置,并显示一个表格,顶部有一个“添加”按钮。 The problem is that when I press the "Add" button, the list of shops appears, but that won't contain any shop, which has already been added to the pivot table for the current user.问题是,当我按下“添加”按钮时,会出现商店列表,但其中不包含任何商店,该商店已添加到当前用户的 pivot 表中。

How could I resolve this in the simplest way?我怎样才能以最简单的方式解决这个问题?

In the RelationController it's being prevented to add multiple times the same link in the pivot table ( https://github.com/wintercms/winter/blob/develop/modules/backend/behaviors/RelationController.php , lines 936-945). In the RelationController it's being prevented to add multiple times the same link in the pivot table ( https://github.com/wintercms/winter/blob/develop/modules/backend/behaviors/RelationController.php , lines 936-945). One solution would be to extend the RelationController, to override that method and to delete these lines.一种解决方案是扩展 RelationController,覆盖该方法并删除这些行。

I used a different approach, where I transformed the pivot table to a regular table.我使用了另一种方法,将 pivot 表转换为常规表。 Now there are one-to-many relationships between visit-user and visit-shop.现在访问用户和访问商店之间存在一对多的关系。 This way it's possible to add the same relationship multiple times.这样就可以多次添加相同的关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM