0

We are using Loopback as a standard RESTFul API.

I have a script that is used to auto-generate the model data based off of discovery of the database tables/structures.

I can generate the schema data for each table, but I don't know how to generate the relations property data for each table, which is important.

For example, this data from a servers/models/model-x.json model schema:

 "validations": [],
  "relations": {    <<<<  definitely need this property to be filled
    "members": {
      "type": "hasMany",
      "model": "user",
      "foreignKey": "memberId"
    }
  },
  "acls": [],
  "methods": {}

so my question is - is it possible to generate this relations data from the tables and the foreign keys in tables? Or is this data too complex to autogenerate?

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

1 Answers1

1

While discovering the schema you set associations: true.

A full code to go through all your database tables and generate the models: Strongloop discovery model still empty

Community
  • 1
  • 1