Skip to content

2.0 throws that model-config.json is using 1.x format; where is the 2.x format? #27

Closed

Description

@STRML

compiler asserts that model configuration objects don't have properties, base, or plural configurations, but the docs show configuration showing these properties.

What properties am I supposed to use?

Activity

  1. raymondfeng commented on Jul 24, 2014

    @raymondfeng
    Member
  2. raymondfeng commented on Jul 24, 2014

    @raymondfeng
    Member

    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": {}
    }
  3. raymondfeng commented on Jul 24, 2014

    @raymondfeng
    Member
  4. STRML commented on Jul 24, 2014

    @STRML
    MemberAuthor

    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.

  5. raymondfeng commented on Jul 24, 2014

    @raymondfeng
    Member

    Do you mean discovery?

  6. STRML commented on Jul 24, 2014

    @STRML
    MemberAuthor

    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.

  7. raymondfeng commented on Jul 24, 2014

    @raymondfeng
    Member

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

  8. STRML commented on Jul 24, 2014

    @STRML
    MemberAuthor

    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 notifications@github.com 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.

  9. raymondfeng commented on Jul 24, 2014

    @raymondfeng
    Member

    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?

  10. bajtos commented on Jul 24, 2014

    @bajtos
    Member

    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 loopback-boot@1.x. 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.
      ]
    });
  11. self-assigned this
    on Jul 24, 2014
  12. raymondfeng commented on Jul 24, 2014

    @raymondfeng
    Member

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

  13. reopened this on Jul 24, 2014
  14. bajtos commented on Jul 25, 2014

    @bajtos
    Member

    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.

  15. bajtos commented on Aug 20, 2014

    @bajtos
    Member

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

  16. ORESoftware commented on Oct 25, 2016

    @ORESoftware

    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

  17. ORESoftware commented on Oct 25, 2016

    @ORESoftware

    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!

  18. crandmck commented on Nov 2, 2016

    @crandmck
  19. bajtos commented on Nov 2, 2016

    @bajtos
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions