Commit Graph

167 Commits

Author SHA1 Message Date
Ryan Graham c467b43c38 Insert copyright headers 2016-04-04 18:14:03 -07:00
sklyukin d0f9b760f5 primaryKey for hasMany and belongsTo relations 2015-09-01 19:03:02 +05:00
sklyukin 483cd873e7 primaryKey to hasOne relation 2015-09-01 01:31:28 +05:00
Satyadeep ad83c82ebc Fixed ReferencesMany .findById to check the given id in the ids array of the model instance 2015-08-19 22:34:16 +05:30
Laurent Villeneuve bdf703fb45 Use idEquals when comparing ids in relation definitions 2015-08-18 10:22:36 -04:00
Laurent Villeneuve 94ff275bbc Handle possible undefined id 2015-08-18 09:40:52 -04:00
Laurent Villeneuve 9363354e0f Fix id copmarison by using strings 2015-08-18 09:40:52 -04:00
Raymond Feng 3ee3ba3dcf Allow 0 as the FK
See https://github.com/strongloop/loopback/issues/967
2015-06-08 13:01:16 -07:00
Patrick Perini e63d15aeb5 addressing #603 2015-05-22 13:42:34 -07:00
Dmitry Manannikov 91b04655cd Fix ReferenceError: definition is not defined
occure when try to delete object in has one relation, but object not created yet
2015-05-22 00:37:27 +03:00
Raymond Feng be38cb3a6f Fix comments 2015-05-18 09:34:25 -07:00
Raymond Feng 93a0342099 Add an optional `options` argument to relation methods 2015-05-16 11:52:17 -07:00
ningsuhen 7861c08e5a add test case for hasmanythrough bi-drectional relations 2015-04-25 01:32:33 +05:30
ningsuhen 9806feb397 Fix for bug - https://github.com/strongloop/loopback-datasource-juggler/issues/571 2015-04-24 15:22:50 +05:30
Partap Davis 29eb3434c7 Promisify model relation methods
When a callback is omitted from a method on a model relation that
supports promises, return that promise.  This includes all the standard
DAO methods, as well as any user-defined methods that return promises.

e.g.:
mylist.todos.create({name: 'Item 1'}) // returns Promise

This API will use native ES6 promises if available.  If not available,
or to force the use of another Promise library, you must assign the
global.Promise object.

e.g.:
global.Promise = require('bluebird')

Relations affected:

- BelongsTo
- HasOne
- HasMany
- HasManyThrough
- HasAndBelongsToMany
- ReferencesMany
- EmbedsOne

Exceptions:

The EmbedsMany relation has not been promisified, because most of the
methods return synchronous values.

The base relation getter method [e.g.: mylist.todos()] has not been
promisified, due to its default caching behavior.

New Methods:

- getAsync(condition, cb)

A new method "getAsync()" has been added to all relations except
EmbedsMany, which always fetches from the datasource rather than from
the cache.  It takes an optional "where" condition (except for HasOne
and BelongsTo) and an optional callback.  If the callback is omitted,
a Promise is returned.
2015-04-07 11:41:07 +02:00
Fabien Franzen 17c8576097 Save parent model of embedded relations 2015-04-01 16:59:21 +02:00
Miroslav Bajtoš 5d8b3323ad Remove all usages of lodash.
This commit is dropping lodash in favour of hand-written implementation
based on ES5 Array methods. As a result, the size of the (unminified)
loopback browser bundle is decreased by approx 360KB.
2015-03-26 09:33:48 +01:00
Raymond Feng 58e7c4e90b Merge pull request #534 from fabien/fix/embeds-many-destroy-all
Properly support embedsMany destroyAll
2015-03-24 09:58:02 -07:00
Raymond Feng 5e0451eef0 Merge pull request #443 from clarkorz/fix/findOrCreate-ThroughModel
Always use findOrCreate when creating a through model
2015-03-24 09:56:07 -07:00
Fabien Franzen aa5943f6b0 Properly support embedsMany destroyAll 2015-03-24 15:39:55 +01:00
Fabien Franzen 73f4a1bbe6 Enable more CRUD remoting methods for embedsOne 2015-03-21 16:23:46 +01:00
Clark Wang 09ee38d613 use findOrCreate for HasManyThrough#create
see strongloop/loopback-connector-mongodb#92

Signed-off-by: Clark Wang <clark.wangs@gmail.com>
2015-03-21 11:49:28 +08:00
Fabien Franzen 54781f376e Enable custom methods on singular relations 2015-03-20 18:15:58 +01:00
Miroslav Bajtoš 52e78ff5ae relation-definition: remove trailing whitespace 2015-02-24 11:36:13 +01:00
Raymond Feng e659e2f603 Fix JS style issues 2015-02-20 14:57:48 -08:00
Bryan Clark 98fcf6b52c use lodash to update the findBelongsTo which now returns an array of matches 2015-02-16 15:36:51 -08:00
Clark Wang 09f7c92cbe use findOrCreate in hasOne#create
So hasOne#create could take advantage from optimized findOrCreate,
which can avoid multiple creation among concurrent requests.

Signed-off-by: Clark Wang <clark.wangs@gmail.com>
2015-02-04 14:54:28 +08:00
Raymond Feng e46bd0cdb5 Fix hasOne remoting 2015-01-29 23:26:11 -08:00
Fabien Franzen a08ef823be Supply target to applyProperties function 2015-01-26 19:09:29 +01:00
Clark Wang 83c3a17f87 support embeds data for belongsTo relation
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
2015-01-19 22:56:09 +08:00
Raymond Feng 4aeb831bd5 Merge pull request #358 from clarkorz/fix/beforeCreate-belongsTo
fix recursive calls if create belongsTo model in beforeCreate hook
2015-01-14 14:42:29 -08:00
Raymond Feng d92905d53e Merge pull request #360 from clarkorz/fix/embedsOne-errors
fix embedsOne error when embed instance is undefined or null
2014-12-03 15:35:18 -08:00
Clark Wang 9d2e6516c3 fix embedsOne error when embed instance is undefined or null
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
2014-11-28 13:45:47 +08:00
Clark Wang 40f03f084b fix recursive calls if create belongsTo model in beforeCreate hook
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
2014-11-24 19:20:38 +08:00
Fabien Franzen 77028b07f8 Be explicit: set RelationDefinition multiple flag 2014-11-24 10:31:28 +01:00
Clark Wang a9cc1c38df Allow hasOne relation to have a scope option
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
2014-11-20 19:27:04 +08:00
Raymond Feng ba29669e0d Merge branch 'fix/350-create-batch-hasmany-relation' of github.com:BuddyHOPP/loopback-datasource-juggler into BuddyHOPP-fix/350-create-batch-hasmany-relation 2014-11-13 12:50:21 -08:00
bitmage d11eacffc6 handle relationship create with [array] 2014-11-11 14:48:34 -07:00
Alex Voitau 5c2468c4ef #350: Creating a batch via hasMany relation is failing. Added handling of array argument. 2014-11-07 18:01:18 -08:00
Pandaiolo 9eaeb9e399 Fix HasOne PK on modelFrom instead of modelTo 2014-10-29 12:06:05 +01:00
Fabien Franzen 5662d9f0c2 Merge pull request #329 from fabien/feature/include-scope
Enable include scope for belongsTo
2014-10-15 18:08:42 +02:00
Fabien Franzen 55d116ec3f Enable include scope for belongsTo 2014-10-14 22:47:59 +02:00
Fabien Franzen 58a6c924b3 Call relation methods in the right context
Before this change, it was impossible to override 'build' and other
(custom) relation/scope methods; only the original prototype method was
ever called.
2014-10-12 22:00:13 +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 7f155966ab Fix to handle new isNewRecord implementation 2014-09-13 00:03:08 +02:00
Raymond Feng 3655107334 Merge pull request #295 from fabien/fix/embeds-many
Various improvements to embedded relations
2014-09-12 10:31:49 -07:00
Raymond Feng af40505703 Merge pull request #290 from fabien/feature/enforce-id
Enforce id (prevent user-set value), fix isNewRecord
2014-09-12 10:31:10 -07:00
Raymond Feng 6903253471 Merge pull request #288 from fabien/fix/relation-tests
Test sync (cached) relation getters
2014-09-12 10:29:42 -07:00
Fabien Franzen e441924fa3 Allow embedsOne to use auto-generated id (from connector)
If the connector has a `generateId` method - like Transient - it can be
used to set the id (when the property has been set to `generated:
true`).
2014-09-07 13:24:05 +02:00
Fabien Franzen 21e1083e88 Implemented persistent: true option for embedsOne 2014-09-07 13:10:23 +02:00