backbone-relational-rails 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -18,12 +18,16 @@ Add the following directive to your Javascript manifest file (application.js):
|
|
18
18
|
|
19
19
|
## Versioning
|
20
20
|
|
21
|
-
backbone-relational-rails 0.
|
21
|
+
backbone-relational-rails 0.7.0 == Backbone-relational 0.7.0
|
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
|
25
25
|
bug be discovered, a 4th version identifier will be added and incremented.
|
26
26
|
|
27
|
+
## Backbone Version
|
28
|
+
|
29
|
+
This release of Backbone-relational is only compatible with Backbone >= 0.9.9.
|
30
|
+
|
27
31
|
## Acknowledgements
|
28
32
|
|
29
33
|
Many thanks to @derekprior for his [tutorial on gemifying assets for Rails](http://prioritized.net/blog/gemify-assets-for-rails/) and his
|
@@ -1,6 +1,7 @@
|
|
1
|
+
/* vim: set tabstop=4:softtabstop=4:shiftwidth=4:noexpandtab */
|
1
2
|
/**
|
2
|
-
* Backbone-relational.js 0.
|
3
|
-
* (c) 2011 Paul Uithol
|
3
|
+
* Backbone-relational.js 0.7.0
|
4
|
+
* (c) 2011-2013 Paul Uithol
|
4
5
|
*
|
5
6
|
* Backbone-relational may be freely distributed under the MIT license; see the accompanying LICENSE.txt.
|
6
7
|
* For details and documentation: https://github.com/PaulUithol/Backbone-relational.
|
@@ -407,7 +408,7 @@
|
|
407
408
|
}
|
408
409
|
|
409
410
|
if ( !this.checkPreconditions() ) {
|
410
|
-
return
|
411
|
+
return;
|
411
412
|
}
|
412
413
|
|
413
414
|
if ( instance ) {
|
@@ -541,7 +542,7 @@
|
|
541
542
|
|
542
543
|
/**
|
543
544
|
* Set the related model(s) for this relation
|
544
|
-
* @param {Backbone.
|
545
|
+
* @param {Backbone.Model|Backbone.Collection} related
|
545
546
|
* @param {Object} [options]
|
546
547
|
*/
|
547
548
|
setRelated: function( related, options ) {
|
@@ -862,7 +863,7 @@
|
|
862
863
|
model = this.relatedModel.findOrCreate( item, { create: this.options.createModels } );
|
863
864
|
}
|
864
865
|
|
865
|
-
if ( model && !this.related.
|
866
|
+
if ( model && !this.related.get( model ) ) {
|
866
867
|
models.push( model );
|
867
868
|
}
|
868
869
|
}, this );
|
@@ -897,7 +898,7 @@
|
|
897
898
|
if (!_.isArray( attr ) && attr !== undefined) {
|
898
899
|
attr = [ attr ];
|
899
900
|
}
|
900
|
-
|
901
|
+
|
901
902
|
_.each( attr, function( attributes ) {
|
902
903
|
newIds[ attributes.id ] = true;
|
903
904
|
});
|
@@ -936,7 +937,7 @@
|
|
936
937
|
|
937
938
|
tryAddRelated: function( model, options ) {
|
938
939
|
options = this.sanitizeOptions( options );
|
939
|
-
if ( !this.related.
|
940
|
+
if ( !this.related.get( model ) ) {
|
940
941
|
// Check if this new model was specified in 'this.keyContents'
|
941
942
|
var item = _.any( this.keyContents || [], function( item ) {
|
942
943
|
var id = Backbone.Relational.store.resolveIdForItem( this.relatedModel, item );
|
@@ -1009,7 +1010,7 @@
|
|
1009
1010
|
var dit = this;
|
1010
1011
|
options = this.unsanitizeOptions( options );
|
1011
1012
|
model.queue( function() { // Queued to avoid errors for adding 'model' to the 'this.related' set twice
|
1012
|
-
if ( dit.related && !dit.related.
|
1013
|
+
if ( dit.related && !dit.related.get( model ) ) {
|
1013
1014
|
dit.related.add( model, options );
|
1014
1015
|
}
|
1015
1016
|
});
|
@@ -1017,7 +1018,7 @@
|
|
1017
1018
|
|
1018
1019
|
removeRelated: function( model, options ) {
|
1019
1020
|
options = this.unsanitizeOptions( options );
|
1020
|
-
if ( this.related.
|
1021
|
+
if ( this.related.get( model ) ) {
|
1021
1022
|
this.related.remove( model, options );
|
1022
1023
|
}
|
1023
1024
|
}
|
@@ -1554,12 +1555,19 @@
|
|
1554
1555
|
* if the collection.model has subModels.
|
1555
1556
|
*/
|
1556
1557
|
Backbone.Collection.prototype.__prepareModel = Backbone.Collection.prototype._prepareModel;
|
1557
|
-
Backbone.Collection.prototype._prepareModel = function (
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1558
|
+
Backbone.Collection.prototype._prepareModel = function ( attrs, options ) {
|
1559
|
+
var model;
|
1560
|
+
|
1561
|
+
if ( attrs instanceof Backbone.Model ) {
|
1562
|
+
if ( !attrs.collection ) {
|
1563
|
+
attrs.collection = this;
|
1564
|
+
}
|
1565
|
+
model = attrs;
|
1566
|
+
}
|
1567
|
+
else {
|
1568
|
+
options || (options = {});
|
1561
1569
|
options.collection = this;
|
1562
|
-
|
1570
|
+
|
1563
1571
|
if ( typeof this.model.findOrCreate !== 'undefined' ) {
|
1564
1572
|
model = this.model.findOrCreate( attrs, options );
|
1565
1573
|
}
|
@@ -1567,16 +1575,14 @@
|
|
1567
1575
|
model = new this.model( attrs, options );
|
1568
1576
|
}
|
1569
1577
|
|
1570
|
-
if ( !model._validate(
|
1578
|
+
if ( !model._validate( attrs, options ) ) {
|
1571
1579
|
model = false;
|
1572
1580
|
}
|
1573
1581
|
}
|
1574
|
-
else if ( !model.collection ) {
|
1575
|
-
model.collection = this;
|
1576
|
-
}
|
1577
1582
|
|
1578
1583
|
return model;
|
1579
|
-
}
|
1584
|
+
};
|
1585
|
+
|
1580
1586
|
|
1581
1587
|
/**
|
1582
1588
|
* Override Backbone.Collection.add, so objects fetched from the server multiple times will
|
@@ -1599,10 +1605,10 @@
|
|
1599
1605
|
model = Backbone.Collection.prototype._prepareModel.call( this, model, options );
|
1600
1606
|
}
|
1601
1607
|
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1608
|
+
if ( model instanceof Backbone.Model && !this.get( model ) ) {
|
1609
|
+
modelsToAdd.push( model );
|
1610
|
+
}
|
1611
|
+
}, this );
|
1606
1612
|
|
1607
1613
|
// Add 'models' in a single batch, so the original add will only be called once (and thus 'sort', etc).
|
1608
1614
|
if ( modelsToAdd.length ) {
|
@@ -1631,7 +1637,7 @@
|
|
1631
1637
|
|
1632
1638
|
//console.debug('calling remove on coll=%o; models=%o, options=%o', this, models, options );
|
1633
1639
|
_.each( models || [], function( model ) {
|
1634
|
-
model = this.
|
1640
|
+
model = this.get( model );
|
1635
1641
|
|
1636
1642
|
if ( model instanceof Backbone.Model ) {
|
1637
1643
|
remove.call( this, model, options );
|
@@ -1674,11 +1680,11 @@
|
|
1674
1680
|
var dit = this, args = arguments;
|
1675
1681
|
|
1676
1682
|
if (eventName === 'add') {
|
1677
|
-
args = _.toArray(args);
|
1683
|
+
args = _.toArray( args );
|
1678
1684
|
// the fourth argument in case of a regular add is the option object.
|
1679
1685
|
// we need to clone it, as it could be modified while we wait on the eventQueue to be unblocked
|
1680
|
-
if (_.isObject(args[3])) {
|
1681
|
-
args[3] = _.clone(args[3]);
|
1686
|
+
if (_.isObject( args[3] ) ) {
|
1687
|
+
args[3] = _.clone( args[3] );
|
1682
1688
|
}
|
1683
1689
|
}
|
1684
1690
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backbone-relational-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -56,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
56
|
version: '0'
|
57
57
|
segments:
|
58
58
|
- 0
|
59
|
-
hash:
|
59
|
+
hash: 4485082081012907281
|
60
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
version: '0'
|
66
66
|
segments:
|
67
67
|
- 0
|
68
|
-
hash:
|
68
|
+
hash: 4485082081012907281
|
69
69
|
requirements: []
|
70
70
|
rubyforge_project:
|
71
71
|
rubygems_version: 1.8.24
|