【问题标题】:Backand - use own db row id as primary keyBackand - 使用自己的数据库行 ID 作为主键
【发布时间】:2016-10-07 18:39:06
【问题描述】:

是否可以在 backand 对象中指定您自己的行 ID?我想在数据库中形成一对一的关系,我有两个对象:userPrivateData 和 userProfile

我想使用 Backands 自己的内部用户对象的 id 作为两个对象的主键。所以基本上是一个userId。原因:使用 REST api,您可以使用 GET /1/objects/{name}/{id}

访问单个项目

由于我不知道行 ID,我想使用另一个唯一标识符作为主键,我知道 - 我的用户 ID。

这可能吗?也许我的概念完全错了,在他们的文档中,他们谈论了很多关于一对多的关系和东西,而不是关于一对一的关系。

【问题讨论】:

    标签: backand


    【解决方案1】:

    我认为您的 JSON 模型看起来像这样。

        [
      {
        "name": "items",
        "fields": {
          "name": {
            "type": "string"
          },
          "description": {
            "type": "text"
          },
          "user": {
            "object": "users"
          }
        }
      },
      {
        "name": "users",
        "fields": {
          "items": {
            "collection": "items",
            "via": "user"
          },
          "allofuserprivatedata": {
            "collection": "userPrivateDataThings",
            "via": "userId"
          },
          "email": {
            "type": "string"
          },
          "firstName": {
            "type": "string"
          },
          "lastName": {
            "type": "string"
          },
          "userProfile": {
            "object": "userProfile"
          }
        }
      },
      {
        "name": "userProfile",
        "fields": {
          "userid": {
            "collection": "users",
            "via": "userProfile"
          },
          "fieldOne": {
            "type": "string"
          },
          "fieldTwo": {
            "type": "boolean"
          }
        }
      },
      {
        "name": "userPrivateDataThings",
        "fields": {
          "field1": {
            "type": "string"
          },
          "field2": {
            "type": "float"
          },
          "userId": {
            "object": "users"
          }
        }
      }
    ]
    

    当你想要一对多时使用集合。 当你想要 1 对 1 时使用一个对象。

    当您使用 deep:true 对用户执行 GET 时,嵌套关系数据将在响应中返回。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-28
      • 1970-01-01
      • 2011-06-10
      • 1970-01-01
      • 1970-01-01
      • 2019-09-04
      • 2015-12-08
      相关资源
      最近更新 更多