Commit Graph

4 Commits

Author SHA1 Message Date
Miroslav Bajtoš b887b33b57 compiler: Move model-sources cfg to models.json
Remove `modelSources` option from `boot()` options, add `_meta.sources`
to `models.json`.

```json
{
  "_meta": {
    "sources": ["./custom/path/to/models"]
  },
  "Car": {
    "dataSource": "db"
  }
}
```
2014-06-16 16:41:12 +02:00
Miroslav Bajtoš a204fdc1c9 Rework model configuration
Rework the way how models are configured, the goal is to allow
loopback-boot to automatically determine the correct order
of the model definitions to ensure base models are defined
before they are extended.

 1. The model .js file no longer creates the model, it exports
 a config function instead:

  ```js
  module.exports = function(Car, Base) {
    // Car is the model constructor
    // Base is the parent model (e.g. loopback.PersistedModel)

    Car.prototype.honk = function(duration, cb) {
      // make some noise for `duration` seconds
      cb();
    };
  };
  ```

 2. The model is created by loopback-boot from model .json file.
  The .js file must have the same base file name.

 3. The `boot()` function has a new parameter `modelSources` to
  specify the list of directories where to look for model definitions.
  The parameter defaults to `['./models']`.

As a side effect, only models configured in `models.json` and their
base clases are defined. This should keep the size of the browserified
bundle small, because unused models are not included.
2014-06-13 19:40:52 +02:00
Miroslav Bajtoš 47b5bb5f5c Change models.json to configure existing models
Breaking change.

In the new 2.x project layout, definition of loopback Models is out of
scope of the boot process. The bootstrapper only configures existing
models - attaches them to a dataSource and the app object.
2014-06-10 09:21:15 +02:00
Miroslav Bajtoš b14800416a Split the boot process into two steps
Split bootLoopBackApp into two steps:
 - compile
 - execute

Most of the changes are just shuffling the existing code around.

What has changed:

 - `loopback.autoAttach()` is called after `models/*` are required.
   The calls were made in the opposite order before this commit.
2014-06-03 08:13:14 +02:00