【发布时间】:2020-04-11 12:42:43
【问题描述】:
我有一个带有自定义属性的序列化程序,我需要包含与该自定义属性的关联,但无法弄清楚:
def dependent_integrations
object.integrations.includes(:service_integrations).where(service_integrations: { master: false}).map do |integration|
# this.integration.organization_integrations ===> I need to include organization_integrations into to integration object for serializer
end
end
并为代码获取此 JSON:
"dependent_integrations": [
{
"id": 2,
"name": "Confluence Cloud",
"key": "confluence-cloud",
"description": "blablaabla",
"vendor": "Atlassian",
"active": true,
"created_at": "2020-04-08T18:16:01.000Z",
"updated_at": "2020-04-08T18:16:03.000Z",
"custom": false
},
]
},
但我需要获取以下包含组织集成的 JSON:
"dependent_integrations": [
{
"id": 2,
"name": "Confluence Cloud",
"key": "confluence-cloud",
"description": "blablaabla",
"vendor": "Atlassian",
"active": true,
"created_at": "2020-04-08T18:16:01.000Z",
"updated_at": "2020-04-08T18:16:03.000Z",
"custom": false,
"organization_integrations": [
{
id: 1,
.......
},
{
id: 2,
.......
}
]
},
.........
]
},
【问题讨论】:
标签: ruby-on-rails active-model-serializers