Commit Graph

321 Commits

Author SHA1 Message Date
Hage Yaapa 464610ef0a feat: add applyDefaultOnWrites property
Adds the ability to ignore writing default values to the database.
2019-08-19 17:11:27 +05:30
Miroslav Bajtoš f1fa976f50
Fix coercion of PK value in `replaceById` method
Before this change, when both the PK value (`id`) and the `data` object
were provided as plain-data values (e.g. as received in a JSON request),
and the connector was using a complex PK type (e.g. `ObjectID`
in MongoDB), then `replaceById` operation was printing confusing
warnings:

    WARNING: id property cannot be changed from 5d39775a59f5f541513c5e05
        to 5d39775a59f5f541513c5e05 for model:Post
        in 'before save' operation hook

    WARNING: id property cannot be changed from 5d39775a59f5f541513c5e05
        to 5d39775a59f5f541513c5e05 for model:Post
        in 'loaded' operation hook

This commit fixes the problem by applying the same type coercion on the
PK value (`id`) as has been applied by the model constructor on the PK
property (`data.id`).

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
2019-07-26 09:02:52 +02:00
Miroslav Bajtoš aa20180c4f
Fix "access" hook for unoptimized "near" queries
Before this change, when an "access" hook modified the "query" object,
the "near" condition from the original "query" object were still
applied. As a result, the query can end up being more restrictive and
return only a subset of models that should have matched the conditions.

With this change in place, after "access" hook observers are invoked,
we update the "near" condition using the "query" object provided by
hook observers.

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
2019-05-14 09:17:54 +02:00
Miroslav Bajtoš 344441d48d
Fix "loaded" hook for unoptimized "near" queries
Before this change, two "loaded" events were emitted for every model
instance found. This commit fixes the problem and restores the intended
behavior.

The bug was probably introduced by 5e0c73bec7.
2019-05-14 09:17:54 +02:00
Agnes Lin de4718d5b8 chore: update copyrights years (#1737) 2019-05-08 11:45:37 -04:00
biniam 9c94b9344b fix: allow coercion of nested properties
Handle model definitions with nested property
definitions for coercion of primitive values.
2019-05-03 18:45:39 -04:00
biniam 48af738ec4 fix: coerce primitive properties on update 2019-04-16 10:51:44 -04:00
Miroslav Bajtoš e45292de08
Do not apply default values on data from database
Before this change, when a property was configured with a default value
at LoopBack side and the database was returned a record with a missing
value for such property, then we would supply use the configured
default.

This behavior is problematic for reasons explained in #1692.

In this commit, we are fixing DAO operations like `find` and
`findOrCreate` so that they do NOT apply default property values on
data returned by the database (connector).

Please note that most of the other CRUD methods were already not
applying default values on database data as long as the connector
provided native implementation of the operation.
2019-04-04 09:47:31 +02:00
biniam 5e0c73bec7 fix: use correct callback for geo find queries 2019-02-14 15:45:13 -05:00
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
Raymond Feng f9131aa18f Use options from request for settings 2018-11-13 12:32:55 -08:00
Raymond Feng f6e1df87be Allow flags to be passed via options 2018-11-09 09:33:05 -08:00
leon3s 65548b6fe0 [ BUGFIX ] maxDepthOfQuery config 2018-11-06 17:29:14 +01:00
Raymond Feng eb85b3e3a6 Allow configuration of maxDepthOfQuery
https://github.com/strongloop/loopback-datasource-juggler/issues/1651
2018-10-31 08:45:16 -07:00
Raymond Feng 8fa7c94605 Improve hidden/protected property checks
- Fixes #1645
  - do not apply hidden property check for data
- Fixes #1648
  - allow prohibitHiddenPropertiesInQuery to be set in model/ds
2018-10-28 10:03:12 -07:00
Raymond Feng 2af2599a7d Allow hidden/protected props as an object
Fixes #1646
2018-10-27 07:51:34 -07:00
Raymond Feng a391762771 Ren handleUndefined to normalizeUndefinedInQuery 2018-10-26 09:09:50 -07:00
Raymond Feng 0ce3f4ead9 Report circular or deep query objects 2018-10-25 15:14:20 -07:00
Raymond Feng a761e0d114 Tidy up extended operator check 2018-10-25 15:14:14 -07:00
Raymond Feng f2e718639a Prevent hidden/protected props from being searched
- report errors if where contains hidden properties
- report errors if incldue scope contains hidden or protected properties
2018-10-19 09:25:47 -07:00
Dimitris eb921ed9d5 remove null in embedded doc properties updates
calling patchAttributes without all embedded properties inits to null
2018-09-24 10:04:09 +03:00
Tom Kirkpatrick 251798c711 fix: ignore extra properties when strict=filter (#1423)
Fix for #1422
2018-08-29 22:57:37 -04:00
Miroslav Bajtoš 7d50f6130b
Upgrade eslint-config-loopback + fix formatting
The new version of our config enabled function-paren-newline rule,
this commit fixes the codebase to use more consistent handling
of newlines when calling functions.
2018-07-16 08:46:25 +02:00
virkt25 9bd7f8d02f
fix: regression on Operation Hooks
Fix the regression introduced by 9af79cf51a where updateAttributes
and replaceAttributes was incorrectly handling the response returned
by the database.

This commit restores the old behaviour where `context.data` is updated
only by a connector-provided function and reverts an incorrect change
of a test file made as part of the faulty fix.

Besides the fixes, this patch also renames `data` to `dbResponse` and
add comments explaining the structure of the response object for more
clarity.
2018-07-09 16:41:56 +02:00
Miroslav Bajtoš 9af79cf51a
Fix Operation Hooks to propagate data changes
Before this change, many Operation Hooks were not correctly propagating
changes made to `ctx.data` via reassigning ctx.data to a new object.

This change modifies existing tests to account for this different
scenario, adds few more tests for scenarios that were not covered by
tests before and finally fixes the problem discovered.
2018-06-28 12:22:16 +02:00
Miroslav Bajtoš d2ee73b9d3
Update eslint + config to latest 2018-06-12 09:13:32 +02:00
Raymond Feng 2b4b44292a Fix tests to ensure compatibility w/ should@10 2018-05-24 14:21:12 -07:00
Kevin Scroggins 07f0310d34 Added error handling for persist operation hook (#1531)
Unrelated CI failures. -.-
2018-01-24 11:37:30 -05:00
Jürg Lehni 0ce1fa9f87 Add a better way to handle transactions 2017-09-06 07:10:57 +02: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
loay 01b4c4a3a7 Catch err using Callback 2017-08-16 17:00:41 -04:00
Raymond Feng 03753b6fe2 Fix undefined properties in where
https://github.com/strongloop/loopback/issues/2364
2017-08-03 14:09:21 -04:00
ssh24 80f015c2d2 Honor backwards compatability with validate update 2017-08-03 11:50:44 -04:00
ssh24 9cd0108fc6 Fix update validation callback 2017-08-02 14:55:47 -04:00
ssh24 b1a0cb8c3b Validate updateAll 2017-08-02 13:24:21 -04:00
loay b1b2d5df0c Catch errors using cb 2017-07-24 14:08:58 -04:00
ssh24 ba1901b2a0 Fix updateAttributes cb
Allow pass through of the new data from the connector
Specifically for cloudant since updateAttributes changes the _rev
2017-05-29 15:32:32 -04:00
Raymond Feng 5a0b0270f3 Return promise for batch create 2017-05-19 16:16:52 -07:00
ssh24 54f67dc3b0 Use correct data on replace callback
Previously, it would just pass the old data
Pass the new data as cloudant updates the _rev property on CRUD
2017-05-18 17:03:21 -04:00
Loay 87dd44dd59 Fix assertion errors 2017-05-04 10:38:06 -04:00
Loay f1d10b47ce Fix forceId bug for updateOrCreate 2017-04-18 13:14:35 -04:00
Joshua Chaitin-Pollak bb3812fbfb Allow `after save` hook to see count of records changed (#1231)
* `after save` hook allows count of records changed

* Fix PR linter
2017-04-06 12:02:34 -04:00
Jonathan Sheely 21b08af7a3 Added notify flag for create and upsert (#1277)
* Added notify flag for create and upsert

* Code styling

* More code styling

* Added unit test for notify

* Fix PR linter
2017-04-05 13:23:26 -04:00
Mikhail 68b93e1074 Disallow regexp string in arrays for coerce (#1279)
Disallow regexp arrays for coerce
2017-03-22 20:29:01 -04:00
Diana Lau eb2cb315e6 FindOrCreate missing error callback 2017-03-20 10:32:09 -04:00
Dimitris 6f8ecfdf5c Fixes #1230 coerceArray converts empty Objects (#1269) 2017-03-20 10:05:11 -04:00
Kevin Delisle 248aaf0541 dao: catch errors on Model creation in find 2017-03-16 17:26:53 -04:00
Kevin Delisle a6c5802940 dao: catch sync errors on setAttributes
Wrap inst.setAttributes in try-catch to prevent synchronous errors
from crashing the application.
2017-03-16 17:26:53 -04:00
Loay 46318d2094 Update error message 2017-03-16 11:02:08 -04:00