strongloop/loopback — pull request #321 by bajtos (2014-06-10 08:21:44+00:00)
Title: Backport from 2.0: create model from config, configure model

This is a back-port of #304 and #308 to 1.x.

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`.

/to @ritch please review. There was a lot of conflicts to resolve, I was carefully comparing diffs to ensure no new stuff from 2.0 would sneak into 1.x.

This patch is needed to make loopback 1.x compatible with loopback-boot 2.0 and the new project layout.