Doctrine多对多 - 如何访问join(pivot)表?

时间:2022-10-05 11:34:42

I'm making many-to many relatioships with categories and articles. But article must have "main" category, so in oters categories "rel="canonical"" to be placed. And logically to place it in join table. In Laravel there is wery simple mechanism to do so: http://laravel.com/docs/5.0/eloquent#working-with-pivot-tables

我正在通过类别和文章制作多对多的关系。但文章必须具有“主要”类别,因此在其他类别中,“rel =”规范“”将被放置。并且逻辑上将它放在连接表中。在Laravel中有一个非常简单的机制:http://laravel.com/docs/5.0/eloquent#working-with-pivot-tables

But I read about association mapping in Doctrine: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html - and there is no info about how to access or modify that table. Is there any way to do this in Doctrine?

但我读到了Doctrine中的关联映射:http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html - 并且没有关于如何访问或修改的信息那张桌子。在Doctrine中有没有办法做到这一点?

1 个解决方案

#1


At the point you are adding another field to the pivot table then it is no longer just a pivot table. You will need to create an entity to access the additional column as there is no way for doctrine to know what to accommodate in an optional 3rd column of a pivot table.

在您向数据透视表添加另一个字段时,它不再仅仅是一个数据透视表。您将需要创建一个实体来访问其他列,因为无法让学说知道在数据透视表的可选第3列中容纳什么。

If you really need to access it then you can just create a raw doctrine query to access the table directly.

如果您确实需要访问它,那么您可以创建一个原始学说查询来直接访问该表。

#1


At the point you are adding another field to the pivot table then it is no longer just a pivot table. You will need to create an entity to access the additional column as there is no way for doctrine to know what to accommodate in an optional 3rd column of a pivot table.

在您向数据透视表添加另一个字段时,它不再仅仅是一个数据透视表。您将需要创建一个实体来访问其他列,因为无法让学说知道在数据透视表的可选第3列中容纳什么。

If you really need to access it then you can just create a raw doctrine query to access the table directly.

如果您确实需要访问它,那么您可以创建一个原始学说查询来直接访问该表。