Skip to content
Browse files

Changed to collectionOptions and accepts an options hash or a function

  • Loading branch information...
1 parent 1a06536 commit c3ddc6a68210966842ab81e4b2283d1d6086372c @ulmus ulmus committed Mar 23, 2012
Showing with 10 additions and 6 deletions.
  1. +4 −3 README.md
  2. +6 −3 backbone-relational.js
View
7 README.md
@@ -171,11 +171,12 @@ By default, the relation's `key` attribute will be used to create a reference to
If you set `collectionKey` to a string, it will use that string as the reference to the RelationalModel, rather than the relation's `key` attribute.
If you don't want this behavior at all, set `collectionKey` to false (or any falsy value) and this reference will not be created.
-### collectionOptionCallback
+### collectionOptions
-Value: a function that accepts an instance of a `Backbone.RelationalModed` and returns an option hash
+Value: an options hash or a function that accepts an instance of a `Backbone.RelationalModed` and returns an option hash
-If supplied, this function should return an option hash that will be used when initializing the collection at the other end of a ToMany-relation. The function will be called with the initialized instance from the first end of the relation as the only argument
+Used to provide options for the initialization of the collection in the "Many"-end of a `HasMany` relation. Can be an options hash or
+a function that should take the instance in the "One"-end of the "HasMany" relation and return an options hash
### includeInJSON
View
9 backbone-relational.js
@@ -653,7 +653,7 @@
reverseRelation: { type: 'HasOne' },
collectionType: Backbone.Collection,
collectionKey: true,
- collectionOptionsCallback: function( instance ){ return {} }
+ collectionOptions: {}
},
initialize: function() {
@@ -668,8 +668,11 @@
if ( !this.collectionType.prototype instanceof Backbone.Collection.prototype.constructor ){
throw new Error( 'collectionType must inherit from Backbone.Collection' );
}
-
- this.setRelated( this.prepareCollection( new this.collectionType( [], this.options.collectionOptionsCallback( this.instance ) ) ) );
+
+ var collectionOptions = _.isFunction( self.options.collectionOptions ) ?
+ self.options.collectionOptions( this.instance ) :
+ self.options.collectionOptions;
+ this.setRelated( this.prepareCollection( new this.collectionType( [], collectionOptions ) ) );
this.findRelated( { silent: true } );
},

0 comments on commit c3ddc6a

Please sign in to comment.
Something went wrong with that request. Please try again.