backbone-relational-rails 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
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.7.
|
21
|
+
backbone-relational-rails 0.7.1 == Backbone-relational 0.7.1
|
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,7 +26,7 @@ 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 >= 0.9.
|
29
|
+
This release of Backbone-relational is only compatible with Backbone >= 0.9.10.
|
30
30
|
|
31
31
|
## Acknowledgements
|
32
32
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
/* vim: set tabstop=4
|
1
|
+
/* vim: set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab: */
|
2
2
|
/**
|
3
|
-
* Backbone-relational.js 0.7.
|
4
|
-
* (c) 2011-2013 Paul Uithol
|
3
|
+
* Backbone-relational.js 0.7.1
|
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.
|
7
7
|
* For details and documentation: https://github.com/PaulUithol/Backbone-relational.
|
@@ -234,8 +234,8 @@
|
|
234
234
|
}
|
235
235
|
|
236
236
|
var coll = _.detect( this._collections, function( c ) {
|
237
|
-
|
238
|
-
|
237
|
+
return c.model === rootModel;
|
238
|
+
});
|
239
239
|
|
240
240
|
if ( !coll ) {
|
241
241
|
coll = this._createCollection( rootModel );
|
@@ -445,6 +445,10 @@
|
|
445
445
|
if ( instance ) {
|
446
446
|
this.initialize();
|
447
447
|
|
448
|
+
if ( options.autoFetch ) {
|
449
|
+
this.instance.fetchRelated( options.key, _.isObject( options.autoFetch ) ? options.autoFetch : {} );
|
450
|
+
}
|
451
|
+
|
448
452
|
// When a model in the store is destroyed, check if it is 'this.instance'.
|
449
453
|
Backbone.Relational.store.getCollection( this.instance )
|
450
454
|
.bind( 'relational:remove', this._modelRemovedFromCollection );
|
@@ -462,7 +466,8 @@
|
|
462
466
|
options: {
|
463
467
|
createModels: true,
|
464
468
|
includeInJSON: true,
|
465
|
-
isAutoRelation: false
|
469
|
+
isAutoRelation: false,
|
470
|
+
autoFetch: false
|
466
471
|
},
|
467
472
|
|
468
473
|
instance: null,
|
@@ -549,7 +554,7 @@
|
|
549
554
|
this.related = related;
|
550
555
|
|
551
556
|
this.instance.acquire();
|
552
|
-
this.instance.
|
557
|
+
this.instance.attributes[ this.key ] = related;
|
553
558
|
this.instance.release();
|
554
559
|
},
|
555
560
|
|
@@ -1313,17 +1318,6 @@
|
|
1313
1318
|
|
1314
1319
|
return result;
|
1315
1320
|
},
|
1316
|
-
|
1317
|
-
/**
|
1318
|
-
* Override 'change', so the change will only execute after 'set' has finised (relations are updated),
|
1319
|
-
* and 'previousAttributes' will be available when the event is fired.
|
1320
|
-
*/
|
1321
|
-
change: function( options ) {
|
1322
|
-
var dit = this, args = arguments;
|
1323
|
-
Backbone.Relational.eventQueue.add( function() {
|
1324
|
-
Backbone.Model.prototype.change.apply( dit, args );
|
1325
|
-
});
|
1326
|
-
},
|
1327
1321
|
|
1328
1322
|
clone: function() {
|
1329
1323
|
var attributes = _.clone( this.attributes );
|
@@ -1522,25 +1516,27 @@
|
|
1522
1516
|
/**
|
1523
1517
|
* Find an instance of `this` type in 'Backbone.Relational.store'.
|
1524
1518
|
* - If `attributes` is a string or a number, `findOrCreate` will just query the `store` and return a model if found.
|
1525
|
-
* - If `attributes` is an object, the model will be updated with `attributes`
|
1519
|
+
* - If `attributes` is an object and is found in the store, the model will be updated with `attributes` unless `options.update` is `false`.
|
1526
1520
|
* Otherwise, a new model is created with `attributes` (unless `options.create` is explicitly set to `false`).
|
1527
1521
|
* @param {Object|String|Number} attributes Either a model's id, or the attributes used to create or update a model.
|
1528
1522
|
* @param {Object} [options]
|
1529
1523
|
* @param {Boolean} [options.create=true]
|
1524
|
+
* @param {Boolean} [options.update=true]
|
1530
1525
|
* @return {Backbone.RelationalModel}
|
1531
1526
|
*/
|
1532
1527
|
findOrCreate: function( attributes, options ) {
|
1528
|
+
options || ( options = {} );
|
1533
1529
|
var parsedAttributes = (_.isObject( attributes ) && this.prototype.parse) ? this.prototype.parse( attributes ) : attributes;
|
1534
1530
|
// Try to find an instance of 'this' model type in the store
|
1535
1531
|
var model = Backbone.Relational.store.find( this, parsedAttributes );
|
1536
1532
|
|
1537
|
-
// If we found an instance, update it with the data in 'item'
|
1538
|
-
// (unless 'options.create' is false).
|
1533
|
+
// If we found an instance, update it with the data in 'item' (unless 'options.update' is false).
|
1534
|
+
// If not, create an instance (unless 'options.create' is false).
|
1539
1535
|
if ( _.isObject( attributes ) ) {
|
1540
|
-
if ( model ) {
|
1536
|
+
if ( model && options.update !== false ) {
|
1541
1537
|
model.set( parsedAttributes, options );
|
1542
1538
|
}
|
1543
|
-
else if ( !
|
1539
|
+
else if ( !model && options.create !== false ) {
|
1544
1540
|
model = this.build( attributes, options );
|
1545
1541
|
}
|
1546
1542
|
}
|
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.7.
|
4
|
+
version: 0.7.1
|
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: -2197334988705490769
|
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: -2197334988705490769
|
69
69
|
requirements: []
|
70
70
|
rubyforge_project:
|
71
71
|
rubygems_version: 1.8.24
|