is it possible to use StrongLoop Arc to create a relationship between two models?

戏子无情 提交于 2019-12-11 10:28:28

问题


In this loopback tutorial we can see how own can create model relationships http://docs.strongloop.com/display/public/LB/Tutorial%3A+model+relations#Tutorial:modelrelations-Createmodelrelations

Is the same possible in StrongLoop Arc?

Thanks


回答1:


Loopback and Arc have sort of different functions. For instance the Loopback framework is a set of Node.js modules that you can use independently or together. While Arc is a visual tool suite for creating, packaging, deploying, profiling, managing, and monitoring Node applications and APIs.

It is not possible to create models in Arc since it is primarily being used to monitor your node application.




回答2:


The short answer is no. The arc branch of the slc ui system is basically their v2 GUI based version of the various other slc cli stuff (slc loopback, slc run, slc debug & slc ctl). It's still pretty limited in features, and thus doesn't support (or display) relations, several other model properties (e.g. auto-generate), etc.

I find slc arc to be pretty limited in its usefulness. I edit the model json files directly for relations and properties. In order to debug, you need to launch your server through slc ctl anyway. For validation you have to edit the model's .js files, etc. The entire system is a moving target, however, so while what I've just stated is true today, next week it could be a different story :).

Note: that while arc in the composer will not display relations or the fields they generate, when it launches the server, the swagger generated api docs will show those relations, and they should work as you expect.




回答3:


You cannot create relations using Arc (unfortunately!). It's sure nice to have.

To create relations you can use the command in the cli from the project's root:

slc loopback:relation

This will prompt you with the models available. You can then select the type of relationship you want to have with the selected models. eg, one to many or many to many. Then you can see the modified .json file in the common folder to view the relations created.

Alternatively, you can also edit the .json file directly. see the example which sets the relation between user and user-tokens

{
  "name": "User",
  .      .
  .
  "relations": {                // relations
    "accessTokens": {           // specify relation name
      "type": "hasMany",        // type of relation
      "model": "AccessToken",   // model to which relation is made
      "foreignKey": "userId"    // foreign key
    }
  }
}


来源:https://stackoverflow.com/questions/31079100/is-it-possible-to-use-strongloop-arc-to-create-a-relationship-between-two-models

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!