Giter Site home page Giter Site logo

Comments (17)

raymondfeng avatar raymondfeng commented on August 20, 2024

The doc needs to be updated. See an example at https://github.com/strongloop/loopback-example-app/blob/master/common/models/car.json

from loopback-boot.

raymondfeng avatar raymondfeng commented on August 20, 2024

The difference is that each json contains one model in 2.0. name becomes a property instead of the key. For example,

1.x:

{
  "myModel": {
    "properties": {}
  }
}

2.x:

{
  "name": "myModel",
  "properties": {}
}

from loopback-boot.

raymondfeng avatar raymondfeng commented on August 20, 2024

Add @bajtos and @crandmck

from loopback-boot.

STRML avatar STRML commented on August 20, 2024

This leads to a very awkward situation when options.models is passed explicitly; I autogenerate model schemas based on a few data sources, and the validator is assuming that I want to use the _meta field and load model configurations from disk. Even if I found a way past the validator, explicit models configuration is ignored in buildAllModelInstructions.

from loopback-boot.

raymondfeng avatar raymondfeng commented on August 20, 2024

Do you mean discovery?

from loopback-boot.

STRML avatar STRML commented on August 20, 2024

Yes, but from a custom connector. I was unable to find satisfactory docs in the past on how to set up autodiscovery 'correctly' so I do some custom model definition munging, which is probably not ideal but should be possible, IMO.

from loopback-boot.

raymondfeng avatar raymondfeng commented on August 20, 2024

Does the custom connector produce the model definition in 1.x format (a json object containing multiple models keyed by model name)?

from loopback-boot.

STRML avatar STRML commented on August 20, 2024

Yes, exactly - I would read in my current models.json, apply updates and inserts, and pass that to app.boot.
On Jul 24, 2014, at 12:22 AM, Raymond Feng [email protected] wrote:

Does the custom connector produce the model definition in 1.x format (a json object containing multiple models keyed by model name)?


Reply to this email directly or view it on GitHub.

from loopback-boot.

raymondfeng avatar raymondfeng commented on August 20, 2024

I wonder if we should add back the ability to define multiple models in one JSON file as 1.x in addition to the 2.x style. What do you think?

from loopback-boot.

bajtos avatar bajtos commented on August 20, 2024

The documentation page "Model definition reference" is wrong, we need to update it for 2.0. Please see Migration guide - models for now.

I wonder if we should add back the ability to define multiple models in one JSON file as 1.x in addition to the 2.x style. What do you think?

I am rather opposed to that idea, it will add more complexity and maintenance overhead. We still need to decouple model definition (properties, options) from model configuration (datasource) for full-stack apps with an isomorphic client, which means the format of such multi-model JSON file will be different from 1.x models.json.

Yes, exactly - I would read in my current models.json, apply updates and inserts, and pass that to app.boot.

This is an interesting use case that I did not consider while working on loopback-boot 2.x.

As an immediate solution/workaround, you can use [email protected]. It is 100% compatible with app.boot from loopback 1.x and it works with loopback 2.x too.

In the longer term, I can extend the options argument of boot/compile to allow you to supply:

  1. Your own model instructions (i.e. an array of objects conforming to what buildAllModelInstructions returns). The compiler will not read any model-related files at all.
  2. Your own model definitions (to replace the result of findModelDefinitions). Together with the existing options.models, it will allow you to specify all model-related data and still use the benefits which loopback-boot provides (most notably loading models in order defined by inheritance, i.e. base models are loaded before models that are extending them).

Thinking about it again, I think the second item is the best.

boot(app, {
  models: {
    Car: { dataSource: 'db' },
    // etc.
  },
  modelDefinitions: [
     {
       definition: {
         name: 'Car',
         properties: { /*...*/ }
       },
       sourceFile: 'path/to/car.js'
    },
    // etc.
  ]
});

from loopback-boot.

raymondfeng avatar raymondfeng commented on August 20, 2024

Maybe we should introduce the ldlVersion into the _meta property so that the boot code can tell which format the json conforms to.

from loopback-boot.

bajtos avatar bajtos commented on August 20, 2024

Maybe we should introduce the ldlVersion into the _meta property so that the boot code can tell which format the json conforms to.

I have considered that too, but since we are able to distinquish 1.x and 2.x even without an explicit version field, I'd rather defer adding that field until it is truly needed.

from loopback-boot.

bajtos avatar bajtos commented on August 20, 2024

There was no activity for almost a month, I am closing the issue. Feel free to reopen if needed.

from loopback-boot.

ORESoftware avatar ORESoftware commented on August 20, 2024

I am having this issue, is there simply a way to explicitly pass model-config.json to

boot(app, {})

?

Something like:

boot(app, {
   modelConfig: require('some-custom-file.json')
})

I am looking at the current docs for this:
https://apidocs.strongloop.com/loopback-boot/

and am not quite seeing it

from loopback-boot.

ORESoftware avatar ORESoftware commented on August 20, 2024

Also, just an aside, in the boot documentation, it's not clear to me what the difference is between model configuration and model definitions:

[models]    Object  
Object containing Model configurations.

[modelDefinitions]  Array   
List of model definitions to use. When options.modelDefinitions is provided, loopback-boot does not search filesystem and use only the models provided in this argument.

anybody care to explain? thanks!

from loopback-boot.

crandmck avatar crandmck commented on August 20, 2024

@davidcheung @deepakrkris ^

from loopback-boot.

bajtos avatar bajtos commented on August 20, 2024

what the difference is between model configuration and model definitions

In short: model configuration is the data in server/model-config.json, model definition is the data from common/models/{name}.json (see also #27 (comment))

from loopback-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.