Miroslav Bajtoš
fcaf19a1d2
Rename hook "query" to "access"
...
The name "query" creates incorrect assumption that hook handlers
may return the result of a query to bypass database access.
That is far from true, since this hook is called also by methods
like `deleteAll` or `updateAll` that don't perform any SELECT query.
2015-02-02 10:41:18 +01:00
Miroslav Bajtoš
370966df99
Implement intent hook `before delete`
...
Methods `DAO.deleteAll` and `DAO.prototype.delete` now invoke
`before delete` hook too. The hook receives `ctx.where` describing
models to be deleted.
2015-02-02 09:13:31 +01:00
Miroslav Bajtoš
842e543bf7
Merge pull request #415 from strongloop/fix/regression-in-dao-save
...
Fix regression in `.save()` from 1fd6eff
2015-01-30 18:28:10 +01:00
Raymond Feng
e41b2d9393
Merge pull request #414 from strongloop/feature/fix-hasone-remoting
...
Fix hasOne remoting
2015-01-30 08:23:46 -08:00
Miroslav Bajtoš
31b9da7d44
Remove redundant `.toObject()` call from `upsert`
2015-01-30 11:31:30 +01:00
Miroslav Bajtoš
5cfbfe3a19
Fix regression in `.save()` from 1fd6eff1
...
The commit 1fd6eff1
(intent-based hooks) introduced a subtle regression
in `.save()` method where dynamic property setters were invoked twice.
This commit fixes the problem by moving pre-save data normalization
into `before save` callback.
2015-01-30 11:31:12 +01:00
Raymond Feng
e46bd0cdb5
Fix hasOne remoting
2015-01-29 23:26:11 -08:00
Raymond Feng
7d42202d40
Make sure batch create calls back with correct data
...
See https://github.com/strongloop/loopback/issues/1031
2015-01-29 11:52:39 -08:00
Miroslav Bajtoš
1fd6eff10f
Intent-based hooks for persistence
...
This patch introduces a new API for "intent-based" hooks. These hooks
are not tied to a particular method (e.g. "find" or "update"). Instead,
they are triggered from all methods that execute a particular "intent".
The consumer API is very simple, there is a new method
Model.observe(name, observer), where the observer is function
observer(context, callback).
Observers are inherited by child models and it is possible to register
multiple observers for the same hook.
List of hooks:
- query
- before save
- after save
- after delete
2015-01-29 08:43:52 +01:00
Fabien Franzen
a19b778cbd
Change Model to BaseModel for clarity
2015-01-08 15:44:28 +01:00
Fabien Franzen
a24b222a72
Don't coerce nested objects into Model instances
...
For queries, this is undesirable. It also affects
loopback-connector-mongodb's ability to perform nested queries (it
expects plain objects to work correctly, and to allow $elemMatch for
example).
2015-01-08 15:34:04 +01:00
Clark Wang
ce2b580ccd
add a flag to callback of findOrCreate to indicate find or create
...
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
2014-12-25 22:19:15 +08:00
Clark Wang
6fa8969912
fix default include in default scope fails findById
...
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
2014-12-11 15:14:35 +08:00
Raymond Feng
48e8ebed7b
Fix a typo
2014-12-03 15:11:27 -08:00
Fabien Franzen
0c28ccedac
Refactored inclusion
...
The syntax is now consistent, regardless of using [] or {} for the
include param.
2014-10-10 14:24:25 +02:00
Fabien Franzen
0e49dc94ec
Allow `attributes` as an alias for `properties` (for LDL)
2014-10-09 18:14:04 +02:00
Fabien Franzen
ec05d0b5a8
Cleanup, consistency: allow properties to be a function
...
Also, pass along the current instance, for any instance method as a
context (save, updateAttributes).
2014-10-09 18:14:04 +02:00
Fabien Franzen
beeb7c46c9
applyProperties => properties (object/false)
2014-10-09 18:14:04 +02:00
Fabien Franzen
49e2b8b8dc
Allow default scope to be a function
2014-10-09 18:14:04 +02:00
Fabien Franzen
b136a8fce7
Full test CRUD suite for default scope
2014-10-09 18:14:04 +02:00
Fabien Franzen
ad55681d69
Properly reset Memory connector cache on automigrate
2014-10-09 18:13:58 +02:00
Fabien Franzen
610866bd7c
Extract mergeQuery and setScopeValuesFromWhere
...
Related to #274 - in preparation of default scope
2014-10-09 18:13:40 +02:00
Fabien Franzen
b4144598bf
DAO save() now uses isNewRecord()
2014-09-05 17:22:14 +02:00
Fabien Franzen
fafe51833b
More fixes/tests
2014-09-05 17:09:23 +02:00
Fabien Franzen
aebf5e9e6b
Enforce id (prevent user-set value), fix isNewRecord
2014-09-05 16:35:01 +02:00
Raymond Feng
057d39d5bb
Simplify the id lookup
2014-09-04 09:32:38 -07:00
Fabien Franzen
86ea107550
Validations configuration as object
...
Previously validations were appended to an array when configured. The
format was cumbersome, and led to issues. This refactors the
configuration into an object, as a property of the Model.
Note that if no validations have been configured, this property is
currently `undefined`.
2014-08-26 17:51:01 +02:00
Fabien Franzen
3b81b928fb
Implement DAO unsetAttribute
2014-08-20 08:57:20 -07:00
Fabien Franzen
a446551a59
Fix relations for RDBMS connectors (mysql, postgresql)
...
- fix tests (explicit model/property definitions)
- fix include vs. RDBMS model strictness
2014-08-20 14:03:38 +02:00
Raymond Feng
7f9108c6d2
Check null
...
See https://github.com/strongloop/loopback-datasource-juggler/issues/223
2014-08-15 23:30:23 -07:00
Fabien Franzen
9f1c5d9c37
Moved DataAccessObject.sortByIds to utils.js
2014-08-15 19:39:58 +02:00
Fabien Franzen
085bb94505
Allow partial list of ids for sortByIds
2014-08-15 19:39:58 +02:00
Fabien Franzen
7cd880712b
Handle toObject in updateAttributes
...
Since one can call updateAttributes with any kind of properties (as
opposed to save, which uses toObject internally), any objects that
correspond to toObject should be handled as such. This is particularly
the case with List objects, as used by embedsMany.
2014-08-15 18:01:40 +02:00
Raymond Feng
c53dc74d16
Fix a name conflict in scope metadata
2014-08-08 15:52:30 -07:00
Fabien Franzen
b18384459a
Implemented findByIds
2014-07-29 15:01:47 +02:00
Fabien Franzen
da303b72a5
Implemented more complex scenaro: embedsMany + relations
...
The test case will denormalize data into the embedded object,
and re-use the actual related object id as its own id.
2014-07-29 12:02:52 +02:00
Raymond Feng
fc710ca55a
Merge branch 'master' into 2.0
2014-07-15 17:09:20 -07:00
Raymond Feng
dc6ada6348
Merge pull request #165 from strongloop/feature/allow-hook-skip-next
...
Pass callback to hooks so that next can be skipped
2014-07-15 12:53:52 -07:00
Raymond Feng
9325ce316b
Allow before hooks to pass arguments to next()
2014-07-15 12:51:33 -07:00
Samuel Reed
b66183f7dc
DAO.prototype.exists should return 'boolean' type.
...
Signed-off-by: Samuel Reed <samuel.trace.reed@gmail.com>
2014-07-08 15:51:24 -05:00
Miroslav Bajtoš
0296ef113d
Make sure 'deleteById' is used as the remote operation name
...
See strongloop/loopback#359
2014-07-03 08:17:01 +02:00
Raymond Feng
f7afade229
Make sure 'upsert' is used as the remote operation name
...
See https://github.com/strongloop/loopback/issues/359
2014-07-02 12:20:56 -07:00
Raymond Feng
e0c7619908
Normalize filter.order and enforce more checks
2014-06-26 23:40:20 -07:00
Raymond Feng
44de2da21f
Merge branch 'master' into 2.0
2014-06-20 23:02:37 -07:00
Raymond Feng
86073cb480
Merge pull request #144 from strongloop/feature/add-update
...
Feature/add update
2014-06-20 12:28:48 -07:00
Raymond Feng
a1836662a7
Clean up comments
2014-06-20 12:05:32 -07:00
Raymond Feng
26501eaa2e
Merge pull request #135 from albertoleal/ConvertNullToNotFoundError
...
ConvertNulltoNotFoundError when calling DataAccessObject.findOne via rest
2014-06-18 23:00:30 -07:00
Raymond Feng
7c71e1e53b
Merge pull request #141 from strongloop/feature/fix-perf
...
Feature/fix perf
2014-06-18 22:40:00 -07:00
Raymond Feng
888d15ce1c
Optimize model instantiation and conversion
2014-06-18 22:13:52 -07:00
Raymond Feng
ad3af82923
Add support for updating multiple instances with query
2014-06-17 16:30:02 -07:00