Commit Graph

117 Commits

Author SHA1 Message Date
Miroslav Bajtoš 9e0f624ad5
manually fix remaining problems 2018-12-07 16:46:15 +01:00
Miroslav Bajtoš 422ec9ad4f
autofix eslint errors 2018-12-07 16:46:15 +01:00
Miroslav Bajtoš 5af4c42728
feat: remove a Model from all registries
Add API allowing consumers (e.g. LoopBack) to remove a Model from all
juggler registries:
 - ModelBuilder's models
 - ModelBuilder's definitions
 - Connector registry of models
2018-04-16 14:24:53 +02:00
Miroslav Bajtoš b0b377af0c
Set model constructor name to model name
Rework the code building model constructors to leverage `Function` class
and dynamically emit a constructor function named after the model.

Before this change, all model classes were called "ModelConstructor",
which made debugging difficult.

After this change, a model class for model "User" is called "User.

Because not all valid model names are also valid JavaScript identifiers,
we implement a simple sanitization technique (replacing characters like
"-", "." and ":" with underscore "_") and fall back to legacy
"ModelConstructor" if the model name is still not a valid JS identifier.
2018-01-08 09:37:23 +01:00
Rashmi Hunt 6c6df15286 Flag id as updateOnly when forceId is in effect (#1453)
* updateOnly, forceId changes

* support getUpdateOnlyProperties

* fixup! fix updateOrCreate in forceId mode

The contract of `updateOrCreate` is expecting a full object instance
to be passed to the callback.

The current implementation was creating an empty instance and
calling updateAttributes under the hood. As a result, the callback
was called with the attributes being updated only.

In order to preserve existing behaviour, we have to always build
a full initial instance by calling `findById`.

See the following discussion for more context:
https://github.com/strongloop/loopback-datasource-juggler/issues/966

* fixup! fix tests of upsert validation

* move forceId to model-builder

* remove TODO comment

* revert refactoring and test fixes

* Remove duplicate test

* change testcase names

* change to ModeClass.settingse

* forceId setup from datasource to model-builder

* fix inheritance of auto-generated forceId

* Fixed failing tests for auto change

* fixed a comment
2017-08-22 13:09:45 -07:00
Kevin Delisle 117152d090 model-builder: JSDoc tidy-up 2017-05-23 10:31:38 -04:00
rashmihunt 52f8fb3416 handle excludeBaseProperties 2017-05-10 12:03:42 -07:00
ebarault 79068d142b configurable model merge
The PR superseeds the existing deepMerge algorithm used to merge
settings of parent and child models with a new algorithm that allows
to specify the way each setting is merged or mixed-in.

This configuration of this algorithm uses a merge policy specification.
The `getMergePolicy()` helper of BaseModelClass can be used to ease
model merge configuration.

Next is presented the expected merge behaviour for each option.
NOTE: This applies to top-level settings properties

- Any
  - `{replace: true}` (default): child replaces the value from parent
  - assignin `null` on child setting deletes the inherited setting

- Arrays
  - `{replace: false}`: unique elements of parent and child cumulate
  - `{rank: true}` adds the model inheritance rank to array
    elements of type Object {} as internal property `__rank`

- Object {}:
  - `{replace: false}`: deep merges parent and child objects
  - `{patch: true}`: child replaces inner properties from parent

The recommended merge policy is returned by getMergePolicy()
when calling the method with option `{configureModelMerge: true}`.

The legacy built-in merge policy is returned by `getMergePolicy()`
when avoiding option `configureModelMerge`.
NOTE: it also delivers ACLs ranking in addition to the legacy
behaviour as well as fixes for settings `description` and `relations`

`getMergePolicy()` can be customized using model's setting
`configureModelMerge` as follows:
```
{
  // ..
  options: {
    configureModelMerge: {
      // merge options
    }
  }
  // ..
}
```

`getMergePolicy()` method can also be extended programmatically as
follows:
```
myModel.getMergePolicy = function(options) {
  const origin = myModel.base.getMergePolicy(options);
  return Object.assign({}, origin, {
    // new/overriding options
  });
};
```
2017-05-10 02:33:45 +02:00
Diana Lau a488a71dbd replace exception thrown for invalid dates 2017-04-21 15:57:11 -04:00
Amir Jafarian aec678d252 Fix manually 2016-08-22 19:20:12 -04:00
Amir Jafarian aa6d28268b Auto-update by eslint --fix 2016-08-22 15:12:25 -04:00
Amir Jafarian 4ce5b5d3a0 Support for globalization 2016-07-28 15:20:18 -04:00
gunjpan 8117b0403f Throw Error for property names with dots
Result of Compat Flags Clenup.
Throws an error for property names with dots, instead
of a deprecation warning.
2016-06-09 17:50:59 -04:00
Amir Jafarian 7a8803cb38 Give warning if PK is changed in hooks
* Give warning if PK is changed in `before save` and `loaded`
 operation hooks for replaceById
2016-06-08 11:56:19 -04:00
Candy 3daca1e960 Remove model events 2016-06-08 10:27:05 -04:00
Dimitris Halatsis b7ba73f1b1 ModelBuilder: add new setting strictEmbeddedModels
The setting controls the strict mode used for embedded property types,
for example the type of "address" property in this model definition:

    modelBuilder.define('TestEmbedded', {
      name: 'string',
      address: {
        street: 'string',
      },
    });
2016-06-01 13:12:50 +02:00
Miroslav Bajtoš 27c6279d6c fix remaining eslint issues 2016-04-05 15:25:34 +02:00
Miroslav Bajtoš 39e04a1756 eslint --fix 2016-04-05 15:25:34 +02:00
Ryan Graham c467b43c38 Insert copyright headers 2016-04-04 18:14:03 -07:00
Jue Hou 0d9eebe3bb Prevent constructor to be property name 2016-02-02 11:51:05 -05:00
Raymond Feng 6eb18cb2f6 Make sure base property definitions are cloned
Sub models sometimes need to customize the properties from the base model.
This change allows each sub model has its own copy of the base property
definition to avoid potential conflicts across multiple sub models of the
same base.
2015-07-10 10:03:51 -07:00
Raymond Feng c609b6d7ce Allow leading slash for `path` in model settings 2015-04-24 08:23:13 -07:00
Miroslav Bajtoš cd7bc46efb Deprecate property names containing a dot 2015-04-02 09:49:04 +02:00
Miroslav Bajtoš 9fd4c00225 Add model setting "persistUndefinedAsNull"
When the setting "persistUndefinedAsNull" is true,
the model will use `null` instead of `undefined` in
all property values.

 - Known optional model properties are set to `null` when no value
   was provided.

 - When setting model properties, `undefined` is always converted
   to `null`. This applies to both known (model-defined) properties
   and additional (custom, dynamic) properties.

 - The instance method `toObject()` converts `undefined` to `null` too.
   Because `toJSON()` calls `toObject()` under the hood, the change
   applies to `toJSON()` too.
2015-03-27 18:25:26 +01:00
Raymond Feng cd1d815936 Use the correct way to iterate over an array
See https://github.com/strongloop/loopback-datasource-juggler/issues/512
2015-03-18 08:21:32 -07:00
Raymond Feng 33d3239b44 Allow submodel to hide base properties 2015-03-03 10:27:22 -08:00
Miroslav Bajtoš 37d7721e0e Deprecate DAO events
List of deprecated events:

 - changed
 - deleted
 - deletedAll
2015-02-27 17:03:39 +01:00
Raymond Feng a8f3d21b65 Merge pull request #436 from strongloop/feature/fix-issue-293
Make sure base properties/settings are merged into the submodel
2015-02-11 16:13:00 -08:00
Raymond Feng ecf84bf802 Enhance the coercion for boolean/date types
See https://github.com/strongloop/loopback-connector-mongodb/issues/90
2015-02-08 10:54:42 -08:00
Raymond Feng cd2bd34619 Make sure base properties/settings are merged into the submodel
See https://github.com/strongloop/loopback-datasource-juggler/issues/293
2015-02-07 11:15:28 -08:00
Raymond Feng bba1ce0768 Merge pull request #405 from clarkorz/fix/id-for-compositeIds
fix id property for composite ids
2015-02-02 08:59:40 -08:00
Miroslav Bajtoš b3d07ebbe8 ModelBaseClass: implement async observe/notify
Implement infrastructure for intent-based hooks.
2015-01-29 08:43:50 +01:00
Clark Wang 2e9e2dd192 fix id property for composite ids
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
2015-01-22 10:39:47 +08:00
Berkeley Martinez 3fac41985b Fix virtual id get function. 2015-01-12 08:43:55 -08:00
Miroslav Bajtoš 14d178bf69 Don't inherit settings.base when extending a model
Fix the bug in `ModelClass.extend` where the `base` option used
in the new class was inherited from ModelClass. As a result
the extended model was incorrectly based on ModelClass's parent.

Modify `modelBuilder.define` to normalize the property name storing
the name of the base model to `settings.base`.
2014-10-10 18:35:18 +02:00
Raymond Feng fe74c8019c Tidy up model building from data sources
See https://github.com/strongloop/loopback/issues/560
2014-09-12 14:25:35 -07:00
Fabien Franzen 39a728be84 Add ability to apply a plugin multiple times from LDL 2014-08-17 12:29:04 +02:00
Rand McKinney 4cb22793e2 Fix links to confluence docs 2014-08-11 11:42:21 -07:00
Raymond Feng f671c9c726 Clean up the mixin processing 2014-08-08 01:20:57 -07:00
Fabien Franzen 35776311fd Unified plugins into mixins
Mixin types: module function, module object, LDL json object.
2014-08-06 13:26:47 +02:00
Fabien Franzen 1a4e8863ef Basic plugin architecture
Similar to http://mongoosejs.com/docs/plugins.html

Next, loopback-boot should be updated to support loading plugins from
dirs.
2014-08-05 16:16:10 +02:00
Fabien Franzen 93aea7eb66 Changed options.path to option.http.path 2014-08-04 19:45:47 +02:00
Fabien Franzen 81a822524d Removed normalization (see strong-remoting) 2014-08-04 12:17:06 +02:00
Fabien Franzen ef65ffee48 Changed normalization api - enabled hasOne remoting 2014-08-01 11:24:41 +02:00
Fabien Franzen 71bf0f8240 Customize/Normalize class-level remoting http path 2014-08-01 09:38:25 +02:00
Raymond Feng 8bc11ca51e Increase the max number of model listeners
See https://github.com/strongloop/loopback/issues/404
2014-07-28 13:02:00 -07:00
Raymond Feng 8f46626c0b Expose base model class as `base` property 2014-07-21 10:21:30 -07:00
Raymond Feng fc710ca55a Merge branch 'master' into 2.0 2014-07-15 17:09:20 -07:00
Raymond Feng a37129bdff Allows default model class to be configured 2014-07-08 14:04:20 -07:00
Raymond Feng 44de2da21f Merge branch 'master' into 2.0 2014-06-20 23:02:37 -07:00