【问题标题】:Graphcool: how to create multifield unique constraints?Graphcool:如何创建多字段唯一约束?
【发布时间】:2019-04-24 02:23:51
【问题描述】:

我想创建多字段约束。与在 SQL 中可能的方式相同,例如通过指定:

CREATE TABLE …. UNIQUE(field1, field2);

所以独一无二的是字段的组合。

是否可以在 Graphcool 中强制执行此约束?

【问题讨论】:

    标签: unique graphcool


    【解决方案1】:

    您可以使用权限查询来实现自定义检查。 例如,您不希望该用户能够在 Post 上添加多个 cmets,因此您希望 Comment.post_id 和 Comment.user_id 是唯一的。为此使用此权限查询

      SomeProposalExists(filter: {
        post: {
          id_not: $input_postId
        }
        user: {
          id_not: $input_userId
        }
      })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-30
      • 1970-01-01
      • 2013-04-30
      • 1970-01-01
      • 2010-09-09
      • 1970-01-01
      • 1970-01-01
      • 2011-01-31
      相关资源
      最近更新 更多