Commit Graph

13 Commits

Author SHA1 Message Date
Raymond Feng 79f504a3c7 Merge branch 'master' into 2.0 2014-07-16 09:09:07 -07:00
Raymond Feng 3c13ce5a8f Refactor modelBuilder to registry and set up default model 2014-07-15 08:37:59 -07:00
Miroslav Bajtoš 7316048afc lib/registry: `getModel` throws, add `findModel`
Rename `loopback.getModel` to `loopback.findModel`.

Implement `loopback.getModel` as a wrapper around `findModel` that
throws an error when the model as not found.
2014-06-16 16:13:24 +02:00
Miroslav Bajtoš 362cceb70a Merge createModelFromConfig with createModel
Merge the two methods `loopback.createModel` and
`loopback.createModelFromConfig` into a single method `createModel`.
2014-06-12 10:41:45 +02:00
Miroslav Bajtoš fc0fad4a9f Add createModelFromConfig and configureModel()
Add new API allowing developers to split the model definition and
configuration into two steps:

 1. Build models from JSON config, export them for re-use:

  ```js
  var Customer = loopback.createModelFromConfig({
    name: 'Customer',
    base: 'User',
    properties: {
      address: 'string'
    }
  });
  ```

 2. Attach existing models to a dataSource and a loopback app,
    modify certain model aspects like relations:

  ```js
  loopback.configureModel(Customer, {
    dataSource: db,
    relations: { /* ... */ }
  });
  ```

Rework `app.model` to use `loopback.configureModel` under the hood.
Here is the new usage:

```js
var Customer = require('./models').Customer;

app.model(Customer, {
  dataSource: 'db',
  relations: { /* ... */ }
});
```

In order to preserve backwards compatibility,
`app.model(name, config)` calls both `createModelFromConfig`
and `configureModel`.
2014-06-12 10:41:44 +02:00
Miroslav Bajtoš 56aab8dbdd Merge createModelFromConfig with createModel
Merge the two methods `loopback.createModel` and
`loopback.createModelFromConfig` into a single method `createModel`.
2014-06-09 11:18:52 +02:00
Miroslav Bajtoš f844459311 Add createModelFromConfig and configureModel()
Add new API allowing developers to split the model definition and
configuration into two steps:

 1. Build models from JSON config, export them for re-use:

  ```js
  var Customer = loopback.createModelFromConfig({
    name: 'Customer',
    base: 'User',
    properties: {
      address: 'string'
    }
  });
  ```

 2. Attach existing models to a dataSource and a loopback app,
    modify certain model aspects like relations:

  ```js
  loopback.configureModel(Customer, {
    dataSource: db,
    relations: { /* ... */ }
  });
  ```

Rework `app.model` to use `loopback.configureModel` under the hood.
Here is the new usage:

```js
var Customer = require('./models').Customer;

app.model(Customer, {
  dataSource: 'db',
  relations: { /* ... */ }
});
```

In order to preserve backwards compatibility with loopback 1.x,
`app.model(name, config)` calls both `createModelFromConfig`
and `configureModel`.
2014-06-05 17:47:28 +02:00
Raymond Feng f08b9427ab Add a test for autoAttach 2014-01-23 15:27:31 -08:00
Raymond Feng bcc7e68e0e Add lookback.getModelByType() and use it resolve model deps 2014-01-23 14:39:27 -08:00
Miroslav Bajtoš 78f514a003 Add ValidationError to loopback exports.
Simplify the construction of validation errors in user-land code:

    var error = new loopback.ValidationError(invalidModel);
2014-01-02 10:35:17 +01:00
Ritchie Martori e7cc30ee03 Fix base class not being actual base class 2013-12-09 17:11:01 -08:00
Raymond Feng 89a2a377c4 Fix the test case 2013-07-23 12:59:40 -07:00
Raymond Feng a35d2b7365 rename asteroid to loopback 2013-07-16 10:42:47 -07:00