【问题标题】:Setting deep associations in normalizr schema在 normalizr 模式中设置深度关联
【发布时间】:2017-06-13 16:58:09
【问题描述】:

我的服务器响应如下所示:

[{
  id: 1,
  title: 'Some Article',
  related_articles: {
    total: 4,
    results: [
      { id: 2, title: 'Some other article' },
      { id: 3, title: 'Yet another article' },
    ]
  }
}]

如您所见,让这件事变得棘手的是它不是一个简单的arrayOf:我想规范化article.related_articles.results

我试过了,没用:

articleSchema.define({
  related_articles: {
    results: arrayOf(relatedArticleSchema),
  },
});

似乎支持的关系必须是“顶级”。

任何人都知道我怎么能以这样的方式结束:

[{
  id: 1,
  title: 'Some Article',
  related_articles: {
    total: 4,
    results: [2, 3]
  }
}]

谢谢!

【问题讨论】:

    标签: javascript reactjs redux normalizr


    【解决方案1】:

    您的方案定义了一个键“relatedArticles”,但它应该是snake_case,“related_articles”

    【讨论】:

    • 啊,令人尴尬的是,看起来问题比那更简单;我只需要重新启动我的服务器,因为该视图是服务器渲染的,所以我的更改实际上并没有被传播。对不起,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-25
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2012-01-05
    • 1970-01-01
    相关资源
    最近更新 更多