在我的应用程序,我有用户。 每个用户都有一个角色(管理员,测试仪,...) 每个角色可以有多个权限(主页视图,contactpage视...)选择实体限制与许多关系的深度
所以,我有一个多对多的关系
因为我想从角色的权限和权限中获得角色,我有双向关系。
我想要的仅仅是选择其角色
我的问题一个权限:当我得到许可,它就会用它与它的角色的权限的每个角色......
结果开始例如:
{
"id": 4,
"nom": "Accès au backoffice",
"slug": "page-backoffice",
"role": [
{
"id": 1,
"libelle": "Administrateur",
"permission": [
{
"id": 3,
"nom": "Visualisation du stock global",
"slug": "page-visu-stock-global",
"role": [
{
"id": 2,
"libelle": "Responsable d'exploitation",
"permission": [
{
.......
我要的是:
{
"id": 4,
"nom": "Accès au backoffice",
"slug": "page-backoffice",
"role": [
{
"id": 1,
"libelle": "Administrateur",
"slug": "administrateur"
},
{
"id": 2,
"libelle": "Responsable d'exploitation",
"slug": "responsable-exploitation"
},
....
哪有我做到了吗?
我的ORM文件关联信息: Permissions.orm.yml:
manyToMany:
role:
targetEntity: Role
cascade: { }
fetch: LAZY
mappedBy: permission
inversedBy: null
joinTable: null
orderBy: null
role.orm.yml:
manyToMany:
permission:
targetEntity: Permissions
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: role
joinTable:
name: role_permission
joinColumns:
-
name: role_id
referencedColumnName: id
inverseJoinColumns:
-
name: permission_id
referencedColumnName: id
orderBy: null
感谢您的帮助
你应该看看的[序列化基团](https://symfony.com/doc/current/components/serializer.html#component-serializer-attributes-groups )和[如何启用它们](https://symfony.com/doc/current/serializer.html#using-serialization-groups-annotations)。希望它可以帮助你 – OlivierC
使用序列化不会阻止教条获取数据做循环权限>角色>权限>角色...我错了吗? –
只有在需要数据时,您才会进行懒读取以获取happend。事实是,你提交了你的对象作为一个JSON,我认为它被序列化为一个API – OlivierC