backbone-relational-rails 0.8.7 → 0.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/README.md +3 -3
- data/lib/backbone-relational-rails/version.rb +1 -1
- data/vendor/assets/javascripts/backbone-relational.js +171 -125
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTRmNmM3YWRjY2Q2NzU3YzAyMzNlNzY2MzY2MzE4ZWU5NDI4YzZmNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZGUwOTE4MDEyZWU0MGJlYzQ5NmM1NTgyZjQyOWU2YTZlMmVjZmQzYg==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Mzc2M2Q2MzZlMTZjMTQ3ODAyMTdkMzIzYTBjOTgxMmNkZjlkMzFkZDI2MWRl
|
10
|
+
N2Q4NTQyYzg1NGM3NTk3YzQzNTllNTExNTc1NDRlNTQ1MWJkMGQ3NjdlMDlk
|
11
|
+
NDM4YzRiOTQwZmIzMDJlNWI3N2IzMzhiYTYwNGNiZmQzNzM2MGM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDIxNTlhYjA5MTYzYzI0NDM4YWQ2M2VjYTFiNjVmYTUxZDg3NjU1NTllMTIw
|
14
|
+
NTUxNzk0Mjc2YWJhNzcxMmUzYzU5Mjk4MjVkMDE4ODY5MTE4N2VkNjY0ODA4
|
15
|
+
ZDkwZjEzNTM4NGEzOWQ0NjlmNzU4Mzg1YjlhNjRlYzhkMTk5ZWE=
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ Add the following directive to your Javascript manifest file (application.js):
|
|
18
18
|
|
19
19
|
## Versioning
|
20
20
|
|
21
|
-
backbone-relational-rails 0.8.
|
21
|
+
backbone-relational-rails 0.8.8 == Backbone-relational 0.8.8
|
22
22
|
|
23
23
|
Every attempt is made to mirror the currently shipping Backbone-relational version number wherever possible.
|
24
24
|
The major, minor, and patch version numbers will always represent the Backbone-relational version. Should a gem
|
@@ -26,9 +26,9 @@ bug be discovered, a 4th version identifier will be added and incremented.
|
|
26
26
|
|
27
27
|
## Backbone Version
|
28
28
|
|
29
|
-
This release of Backbone-relational is only compatible with Backbone >= 1.
|
29
|
+
This release of Backbone-relational is only compatible with Backbone >= 1.1.2.
|
30
30
|
|
31
31
|
## Acknowledgements
|
32
32
|
|
33
|
-
Many thanks to @derekprior for his [tutorial on gemifying assets for Rails](http://prioritized.net/blog/gemify-assets-for-rails/) and his
|
33
|
+
Many thanks to [@derekprior](http://github.com/derekprior) for his [tutorial on gemifying assets for Rails](http://prioritized.net/blog/gemify-assets-for-rails/) and his
|
34
34
|
[momentjs-rails gem](http://github.com/derekprior/momentjs-rails).
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* vim: set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab: */
|
2
2
|
/**
|
3
|
-
* Backbone-relational.js 0.8.
|
3
|
+
* Backbone-relational.js 0.8.8
|
4
4
|
* (c) 2011-2013 Paul Uithol and contributors (https://github.com/PaulUithol/Backbone-relational/graphs/contributors)
|
5
5
|
*
|
6
6
|
* Backbone-relational may be freely distributed under the MIT license; see the accompanying LICENSE.txt.
|
@@ -9,60 +9,57 @@
|
|
9
9
|
*
|
10
10
|
* Example:
|
11
11
|
*
|
12
|
-
Zoo = Backbone.RelationalModel.extend(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}
|
28
|
-
|
29
|
-
Animal = Backbone.RelationalModel.extend(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
12
|
+
Zoo = Backbone.RelationalModel.extend({
|
13
|
+
relations: [ {
|
14
|
+
type: Backbone.HasMany,
|
15
|
+
key: 'animals',
|
16
|
+
relatedModel: 'Animal',
|
17
|
+
reverseRelation: {
|
18
|
+
key: 'livesIn',
|
19
|
+
includeInJSON: 'id'
|
20
|
+
// 'relatedModel' is automatically set to 'Zoo'; the 'relationType' to 'HasOne'.
|
21
|
+
}
|
22
|
+
} ],
|
23
|
+
|
24
|
+
toString: function() {
|
25
|
+
return this.get( 'name' );
|
26
|
+
}
|
27
|
+
});
|
28
|
+
|
29
|
+
Animal = Backbone.RelationalModel.extend({
|
30
|
+
toString: function() {
|
31
|
+
return this.get( 'species' );
|
32
|
+
}
|
33
|
+
});
|
34
34
|
|
35
35
|
// Creating the zoo will give it a collection with one animal in it: the monkey.
|
36
36
|
// The animal created after that has a relation `livesIn` that points to the zoo it's currently associated with.
|
37
37
|
// If you instantiate (or fetch) the zebra later, it will automatically be added.
|
38
38
|
|
39
|
-
var zoo = new Zoo(
|
40
|
-
|
41
|
-
|
42
|
-
}
|
39
|
+
var zoo = new Zoo({
|
40
|
+
name: 'Artis',
|
41
|
+
animals: [ { id: 'monkey-1', species: 'Chimp' }, 'lion-1', 'zebra-1' ]
|
42
|
+
});
|
43
43
|
|
44
44
|
var lion = new Animal( { id: 'lion-1', species: 'Lion' } ),
|
45
|
-
|
46
|
-
|
45
|
+
monkey = zoo.get( 'animals' ).first(),
|
46
|
+
sameZoo = lion.get( 'livesIn' );
|
47
47
|
*/
|
48
|
-
( function(
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
_ = require( 'underscore' );
|
57
|
-
Backbone = require( 'backbone' );
|
58
|
-
exports = Backbone;
|
59
|
-
typeof module === 'undefined' || ( module.exports = exports );
|
48
|
+
( function( root, factory ) {
|
49
|
+
// Set up Backbone-relational for the environment. Start with AMD.
|
50
|
+
if ( typeof define === 'function' && define.amd ) {
|
51
|
+
define( [ 'exports', 'backbone', 'underscore' ], factory );
|
52
|
+
}
|
53
|
+
// Next for Node.js or CommonJS.
|
54
|
+
else if ( typeof exports !== 'undefined' ) {
|
55
|
+
factory( exports, require( 'backbone' ), require( 'underscore' ) );
|
60
56
|
}
|
57
|
+
// Finally, as a browser global. Use `root` here as it references `window`.
|
61
58
|
else {
|
62
|
-
|
63
|
-
Backbone = window.Backbone;
|
64
|
-
exports = window;
|
59
|
+
factory( root, root.Backbone, root._ );
|
65
60
|
}
|
61
|
+
}( this, function( exports, Backbone, _ ) {
|
62
|
+
"use strict";
|
66
63
|
|
67
64
|
Backbone.Relational = {
|
68
65
|
showWarnings: true
|
@@ -230,7 +227,7 @@
|
|
230
227
|
*/
|
231
228
|
setupSuperModel: function( modelType ) {
|
232
229
|
_.find( this._subModels, function( subModelDef ) {
|
233
|
-
return _.
|
230
|
+
return _.filter( subModelDef.subModels || [], function( subModelTypeName, typeValue ) {
|
234
231
|
var subModelType = this.getObjectByName( subModelTypeName );
|
235
232
|
|
236
233
|
if ( modelType === subModelType ) {
|
@@ -243,7 +240,7 @@
|
|
243
240
|
modelType._subModelTypeAttribute = subModelDef.superModelType.prototype.subModelTypeAttribute;
|
244
241
|
return true;
|
245
242
|
}
|
246
|
-
}, this );
|
243
|
+
}, this ).length;
|
247
244
|
}, this );
|
248
245
|
},
|
249
246
|
|
@@ -349,8 +346,8 @@
|
|
349
346
|
rootModel = rootModel._superModel;
|
350
347
|
}
|
351
348
|
|
352
|
-
var coll = _.find( this._collections, function(item) {
|
353
|
-
|
349
|
+
var coll = _.find( this._collections, function( item ) {
|
350
|
+
return item.model === rootModel;
|
354
351
|
});
|
355
352
|
|
356
353
|
if ( !coll && create !== false ) {
|
@@ -459,8 +456,6 @@
|
|
459
456
|
if ( coll ) {
|
460
457
|
var modelColl = model.collection;
|
461
458
|
coll.add( model );
|
462
|
-
this.listenTo( model, 'destroy', this.unregister, this );
|
463
|
-
this.listenTo( model, 'relational:unregister', this.unregister, this );
|
464
459
|
model.collection = modelColl;
|
465
460
|
}
|
466
461
|
},
|
@@ -489,6 +484,12 @@
|
|
489
484
|
*/
|
490
485
|
update: function( model ) {
|
491
486
|
var coll = this.getCollection( model );
|
487
|
+
|
488
|
+
// Register a model if it isn't yet (which happens if it was created without an id).
|
489
|
+
if ( !coll.contains( model ) ) {
|
490
|
+
this.register( model );
|
491
|
+
}
|
492
|
+
|
492
493
|
// This triggers updating the lookup indices kept in a collection
|
493
494
|
coll._onModelEvent( 'change:' + model.idAttribute, model, coll );
|
494
495
|
|
@@ -497,20 +498,47 @@
|
|
497
498
|
},
|
498
499
|
|
499
500
|
/**
|
500
|
-
*
|
501
|
-
* @param {Backbone.RelationalModel}
|
502
|
-
* @param {Backbone.Collection} [collection]
|
503
|
-
* @param {Object} [options]
|
501
|
+
* Unregister from the store: a specific model, a collection, or a model type.
|
502
|
+
* @param {Backbone.RelationalModel|Backbone.RelationalModel.constructor|Backbone.Collection} type
|
504
503
|
*/
|
505
|
-
unregister: function(
|
506
|
-
|
504
|
+
unregister: function( type ) {
|
505
|
+
var coll,
|
506
|
+
models;
|
507
507
|
|
508
|
-
|
509
|
-
|
510
|
-
|
508
|
+
if ( type instanceof Backbone.Model ) {
|
509
|
+
coll = this.getCollection( type );
|
510
|
+
models = [ type ];
|
511
|
+
}
|
512
|
+
else if ( type instanceof Backbone.Collection ) {
|
513
|
+
coll = this.getCollection( type.model );
|
514
|
+
models = _.clone( type.models );
|
515
|
+
}
|
516
|
+
else {
|
517
|
+
coll = this.getCollection( type );
|
518
|
+
models = _.clone( coll.models );
|
519
|
+
}
|
511
520
|
|
512
|
-
|
513
|
-
|
521
|
+
_.each( models, function( model ) {
|
522
|
+
this.stopListening( model );
|
523
|
+
_.invoke( model.getRelations(), 'stopListening' );
|
524
|
+
}, this );
|
525
|
+
|
526
|
+
|
527
|
+
// If we've unregistered an entire store collection, reset the collection (which is much faster).
|
528
|
+
// Otherwise, remove each model one by one.
|
529
|
+
if ( _.contains( this._collections, type ) ) {
|
530
|
+
coll.reset( [] );
|
531
|
+
}
|
532
|
+
else {
|
533
|
+
_.each( models, function( model ) {
|
534
|
+
if ( coll.get( model ) ) {
|
535
|
+
coll.remove( model );
|
536
|
+
}
|
537
|
+
else {
|
538
|
+
coll.trigger( 'relational:remove', model, coll );
|
539
|
+
}
|
540
|
+
}, this );
|
541
|
+
}
|
514
542
|
},
|
515
543
|
|
516
544
|
/**
|
@@ -519,6 +547,12 @@
|
|
519
547
|
*/
|
520
548
|
reset: function() {
|
521
549
|
this.stopListening();
|
550
|
+
|
551
|
+
// Unregister each collection to remove event listeners
|
552
|
+
_.each( this._collections, function( coll ) {
|
553
|
+
this.unregister( coll );
|
554
|
+
}, this );
|
555
|
+
|
522
556
|
this._collections = [];
|
523
557
|
this._subModels = [];
|
524
558
|
this._modelScopes = [ exports ];
|
@@ -684,10 +718,7 @@
|
|
684
718
|
*/
|
685
719
|
setRelated: function( related ) {
|
686
720
|
this.related = related;
|
687
|
-
|
688
|
-
this.instance.acquire();
|
689
721
|
this.instance.attributes[ this.key ] = related;
|
690
|
-
this.instance.release();
|
691
722
|
},
|
692
723
|
|
693
724
|
/**
|
@@ -713,10 +744,10 @@
|
|
713
744
|
var models = !_.isUndefined( model ) ? [ model ] : this.related && ( this.related.models || [ this.related ] );
|
714
745
|
_.each( models || [], function( related ) {
|
715
746
|
_.each( related.getRelations() || [], function( relation ) {
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
747
|
+
if ( this._isReverseRelation( relation ) ) {
|
748
|
+
reverseRelations.push( relation );
|
749
|
+
}
|
750
|
+
}, this );
|
720
751
|
}, this );
|
721
752
|
|
722
753
|
return reverseRelations;
|
@@ -1049,7 +1080,7 @@
|
|
1049
1080
|
/**
|
1050
1081
|
* When a model is added to a 'HasMany', trigger 'add' on 'this.instance' and notify reverse relations.
|
1051
1082
|
* (should be 'HasOne', must set 'this.instance' as their related).
|
1052
|
-
|
1083
|
+
*/
|
1053
1084
|
handleAddition: function( model, coll, options ) {
|
1054
1085
|
//console.debug('handleAddition called; args=%o', arguments);
|
1055
1086
|
options = options ? _.clone( options ) : {};
|
@@ -1081,7 +1112,7 @@
|
|
1081
1112
|
|
1082
1113
|
var dit = this;
|
1083
1114
|
!options.silent && Backbone.Relational.eventQueue.add( function() {
|
1084
|
-
|
1115
|
+
dit.instance.trigger( 'remove:' + dit.key, model, dit.related, options );
|
1085
1116
|
});
|
1086
1117
|
},
|
1087
1118
|
|
@@ -1145,7 +1176,7 @@
|
|
1145
1176
|
// Example: event for "p.on( 'add:jobs' )" -> "p.get('jobs').add( { company: c.id, person: p.id } )".
|
1146
1177
|
if ( options && options.collection ) {
|
1147
1178
|
var dit = this,
|
1148
|
-
collection = this.collection =
|
1179
|
+
collection = this.collection = options.collection;
|
1149
1180
|
|
1150
1181
|
// Prevent `collection` from cascading down to nested models; they shouldn't go into this `if` clause.
|
1151
1182
|
delete options.collection;
|
@@ -1168,6 +1199,7 @@
|
|
1168
1199
|
}
|
1169
1200
|
|
1170
1201
|
Backbone.Relational.store.processOrphanRelations();
|
1202
|
+
Backbone.Relational.store.listenTo( this, 'relational:unregister', Backbone.Relational.store.unregister );
|
1171
1203
|
|
1172
1204
|
this._queue = new Backbone.BlockingQueue();
|
1173
1205
|
this._queue.block();
|
@@ -1190,47 +1222,53 @@
|
|
1190
1222
|
var dit = this,
|
1191
1223
|
args = arguments;
|
1192
1224
|
|
1193
|
-
Backbone.Relational.eventQueue.
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1225
|
+
if ( !Backbone.Relational.eventQueue.isLocked() ) {
|
1226
|
+
// If we're not in a more complicated nested scenario, fire the change event right away
|
1227
|
+
Backbone.Model.prototype.trigger.apply( dit, args );
|
1228
|
+
}
|
1229
|
+
else {
|
1230
|
+
Backbone.Relational.eventQueue.add( function() {
|
1231
|
+
// Determine if the `change` event is still valid, now that all relations are populated
|
1232
|
+
var changed = true;
|
1233
|
+
if ( eventName === 'change' ) {
|
1234
|
+
// `hasChanged` may have gotten reset by nested calls to `set`.
|
1235
|
+
changed = dit.hasChanged() || dit._attributeChangeFired;
|
1236
|
+
dit._attributeChangeFired = false;
|
1237
|
+
}
|
1238
|
+
else {
|
1239
|
+
var attr = eventName.slice( 7 ),
|
1240
|
+
rel = dit.getRelation( attr );
|
1241
|
+
|
1242
|
+
if ( rel ) {
|
1243
|
+
// If `attr` is a relation, `change:attr` get triggered from `Relation.onChange`.
|
1244
|
+
// These take precedence over `change:attr` events triggered by `Model.set`.
|
1245
|
+
// The relation sets a fourth attribute to `true`. If this attribute is present,
|
1246
|
+
// continue triggering this event; otherwise, it's from `Model.set` and should be stopped.
|
1247
|
+
changed = ( args[ 4 ] === true );
|
1248
|
+
|
1249
|
+
// If this event was triggered by a relation, set the right value in `this.changed`
|
1250
|
+
// (a Collection or Model instead of raw data).
|
1251
|
+
if ( changed ) {
|
1252
|
+
dit.changed[ attr ] = args[ 2 ];
|
1253
|
+
}
|
1254
|
+
// Otherwise, this event is from `Model.set`. If the relation doesn't report a change,
|
1255
|
+
// remove attr from `dit.changed` so `hasChanged` doesn't take it into account.
|
1256
|
+
else if ( !rel.changed ) {
|
1257
|
+
delete dit.changed[ attr ];
|
1258
|
+
}
|
1220
1259
|
}
|
1221
|
-
|
1222
|
-
|
1223
|
-
else if ( !rel.changed ) {
|
1224
|
-
delete dit.changed[ attr ];
|
1260
|
+
else if ( changed ) {
|
1261
|
+
dit._attributeChangeFired = true;
|
1225
1262
|
}
|
1226
1263
|
}
|
1227
|
-
else if ( changed ) {
|
1228
|
-
dit._attributeChangeFired = true;
|
1229
|
-
}
|
1230
|
-
}
|
1231
1264
|
|
1232
|
-
|
1233
|
-
|
1265
|
+
changed && Backbone.Model.prototype.trigger.apply( dit, args );
|
1266
|
+
});
|
1267
|
+
}
|
1268
|
+
}
|
1269
|
+
else if ( eventName === 'destroy' ) {
|
1270
|
+
Backbone.Model.prototype.trigger.apply( this, arguments );
|
1271
|
+
Backbone.Relational.store.unregister( this );
|
1234
1272
|
}
|
1235
1273
|
else {
|
1236
1274
|
Backbone.Model.prototype.trigger.apply( this, arguments );
|
@@ -1417,8 +1455,8 @@
|
|
1417
1455
|
|
1418
1456
|
// Go through all splits and return the final result
|
1419
1457
|
var splits = attr.split( '.' );
|
1420
|
-
var result = _.reduce(splits, function( model, split ) {
|
1421
|
-
if ( _.isNull(model) || _.isUndefined( model ) ) {
|
1458
|
+
var result = _.reduce( splits, function( model, split ) {
|
1459
|
+
if ( _.isNull( model ) || _.isUndefined( model ) ) {
|
1422
1460
|
// Return undefined if the path cannot be expanded
|
1423
1461
|
return undefined;
|
1424
1462
|
}
|
@@ -1466,7 +1504,12 @@
|
|
1466
1504
|
// Ideal place to set up relations, if this is the first time we're here for this model
|
1467
1505
|
if ( !this._isInitialized && !this.isLocked() ) {
|
1468
1506
|
this.constructor.initializeModelHierarchy();
|
1469
|
-
|
1507
|
+
|
1508
|
+
// Only register models that have an id. A model will be registered when/if it gets an id later on.
|
1509
|
+
if ( newId || newId === 0 ) {
|
1510
|
+
Backbone.Relational.store.register( this );
|
1511
|
+
}
|
1512
|
+
|
1470
1513
|
this.initializeRelations( options );
|
1471
1514
|
}
|
1472
1515
|
// The store should know about an `id` update asap
|
@@ -1538,7 +1581,7 @@
|
|
1538
1581
|
if ( rel instanceof Backbone.HasMany ) {
|
1539
1582
|
value = value.concat( rel.keyIds );
|
1540
1583
|
}
|
1541
|
-
else if
|
1584
|
+
else if ( rel instanceof Backbone.HasOne ) {
|
1542
1585
|
value = value || rel.keyId;
|
1543
1586
|
|
1544
1587
|
if ( !value && !_.isObject( rel.keyContents ) ) {
|
@@ -1705,7 +1748,7 @@
|
|
1705
1748
|
|
1706
1749
|
inheritRelations: function() {
|
1707
1750
|
// Bail out if we've been here before.
|
1708
|
-
if (!_.isUndefined( this._superModel ) && !_.isNull( this._superModel )) {
|
1751
|
+
if ( !_.isUndefined( this._superModel ) && !_.isNull( this._superModel ) ) {
|
1709
1752
|
return;
|
1710
1753
|
}
|
1711
1754
|
// Try to initialize the _superModel.
|
@@ -1738,7 +1781,7 @@
|
|
1738
1781
|
|
1739
1782
|
/**
|
1740
1783
|
* Find an instance of `this` type in 'Backbone.Relational.store'.
|
1741
|
-
* A new model is created
|
1784
|
+
* A new model is created if no matching model is found, `attributes` is an object, and `options.create` is true.
|
1742
1785
|
* - If `attributes` is a string or a number, `findOrCreate` will query the `store` and return a model if found.
|
1743
1786
|
* - If `attributes` is an object and is found in the store, the model will be updated with `attributes` unless `options.update` is `false`.
|
1744
1787
|
* @param {Object|String|Number} attributes Either a model's id, or the attributes used to create or update a model.
|
@@ -1768,7 +1811,7 @@
|
|
1768
1811
|
model.set( parsedAttributes, options );
|
1769
1812
|
}
|
1770
1813
|
else if ( !model && options.create !== false ) {
|
1771
|
-
model = this.build(
|
1814
|
+
model = this.build( parsedAttributes, _.defaults( { parse: false }, options ) );
|
1772
1815
|
}
|
1773
1816
|
}
|
1774
1817
|
|
@@ -1810,7 +1853,7 @@
|
|
1810
1853
|
* (which sets the new properties on it if found), or instantiates a new model.
|
1811
1854
|
*/
|
1812
1855
|
Backbone.Collection.prototype.__prepareModel = Backbone.Collection.prototype._prepareModel;
|
1813
|
-
Backbone.Collection.prototype._prepareModel = function
|
1856
|
+
Backbone.Collection.prototype._prepareModel = function( attrs, options ) {
|
1814
1857
|
var model;
|
1815
1858
|
|
1816
1859
|
if ( attrs instanceof Backbone.Model ) {
|
@@ -1855,11 +1898,12 @@
|
|
1855
1898
|
models = this.parse( models, options );
|
1856
1899
|
}
|
1857
1900
|
|
1858
|
-
|
1859
|
-
|
1860
|
-
var newModels = [],
|
1901
|
+
var singular = !_.isArray( models ),
|
1902
|
+
newModels = [],
|
1861
1903
|
toAdd = [];
|
1862
1904
|
|
1905
|
+
models = singular ? ( models ? [ models ] : [] ) : _.clone( models );
|
1906
|
+
|
1863
1907
|
//console.debug( 'calling add on coll=%o; model=%o, options=%o', this, models, options );
|
1864
1908
|
_.each( models, function( model ) {
|
1865
1909
|
if ( !( model instanceof Backbone.Model ) ) {
|
@@ -1882,6 +1926,7 @@
|
|
1882
1926
|
|
1883
1927
|
// Add 'models' in a single batch, so the original add will only be called once (and thus 'sort', etc).
|
1884
1928
|
// If `parse` was specified, the collection and contained models have been parsed now.
|
1929
|
+
toAdd = singular ? ( toAdd.length ? toAdd[ 0 ] : null ) : toAdd;
|
1885
1930
|
var result = set.call( this, toAdd, _.defaults( { parse: false }, options ) );
|
1886
1931
|
|
1887
1932
|
_.each( newModels, function( model ) {
|
@@ -1904,10 +1949,11 @@
|
|
1904
1949
|
return remove.apply( this, arguments );
|
1905
1950
|
}
|
1906
1951
|
|
1907
|
-
|
1908
|
-
|
1952
|
+
var singular = !_.isArray( models ),
|
1953
|
+
toRemove = [];
|
1909
1954
|
|
1910
|
-
|
1955
|
+
models = singular ? ( models ? [ models ] : [] ) : _.clone( models );
|
1956
|
+
options || ( options = {} );
|
1911
1957
|
|
1912
1958
|
//console.debug('calling remove on coll=%o; models=%o, options=%o', this, models, options );
|
1913
1959
|
_.each( models, function( model ) {
|
@@ -1915,10 +1961,10 @@
|
|
1915
1961
|
model && toRemove.push( model );
|
1916
1962
|
}, this );
|
1917
1963
|
|
1918
|
-
var result = remove.call( this, toRemove, options );
|
1964
|
+
var result = remove.call( this, singular ? ( toRemove.length ? toRemove[ 0 ] : null ) : toRemove, options );
|
1919
1965
|
|
1920
1966
|
_.each( toRemove, function( model ) {
|
1921
|
-
this.trigger('relational:remove', model, this, options);
|
1967
|
+
this.trigger( 'relational:remove', model, this, options );
|
1922
1968
|
}, this );
|
1923
1969
|
|
1924
1970
|
return result;
|
@@ -1994,4 +2040,4 @@
|
|
1994
2040
|
|
1995
2041
|
return child;
|
1996
2042
|
};
|
1997
|
-
})
|
2043
|
+
}));
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backbone-relational-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Marsh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - '>='
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - '>='
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.1'
|
27
27
|
description: Backbone-relational provides one-to-one, one-to-many and many-to-one
|
@@ -32,11 +32,11 @@ executables: []
|
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
-
- lib/backbone-relational-rails/version.rb
|
36
|
-
- lib/backbone-relational-rails.rb
|
37
|
-
- vendor/assets/javascripts/backbone-relational.js
|
38
35
|
- LICENSE
|
39
36
|
- README.md
|
37
|
+
- lib/backbone-relational-rails.rb
|
38
|
+
- lib/backbone-relational-rails/version.rb
|
39
|
+
- vendor/assets/javascripts/backbone-relational.js
|
40
40
|
homepage: http://github.com/petedmarsh/backbone-relational-rails
|
41
41
|
licenses:
|
42
42
|
- MIT
|
@@ -48,17 +48,17 @@ require_paths:
|
|
48
48
|
- vendor
|
49
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - '>='
|
51
|
+
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
55
|
requirements:
|
56
|
-
- - '>='
|
56
|
+
- - ! '>='
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
60
|
rubyforge_project:
|
61
|
-
rubygems_version: 2.0
|
61
|
+
rubygems_version: 2.2.0
|
62
62
|
signing_key:
|
63
63
|
specification_version: 4
|
64
64
|
summary: Backbone-relational packaged for Rails
|