Pankaj Bodani
Pankaj Bodani

Reputation: 303

How to create relationship using Strongloop strong arc?

How can I create relationships via slc or by directly editing models in a text editor?

I could not find a way to do so using strong arc composer. Does this feature exist?

Upvotes: 0

Views: 216

Answers (1)

Anoop Thiruonam
Anoop Thiruonam

Reputation: 2872

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
    }
  }
}

Upvotes: 2

Related Questions