From 7503daedd177803235506c063cfd5b69b9f4b490 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Thu, 15 Dec 2016 12:53:26 +0000 Subject: [PATCH] WP-API: JavaScript client - fix setup of models used by wp.api.collections objects. Correct setup for the `model` attribute of `wp.api.collections` objects. Set the collection model as a function that returns a new model of the underlying type, instead of setting it as the model prototype. Fixes an issue where models for fetched collections weren't set up properly and didn't have the expected mixin methods such as `getCategories` available. Props jesseenterprises. Fixes #39070. git-svn-id: https://develop.svn.wordpress.org/trunk@39603 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/wp-api.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/js/wp-api.js b/src/wp-includes/js/wp-api.js index a14d21fae6..717ebf8e06 100644 --- a/src/wp-includes/js/wp-api.js +++ b/src/wp-includes/js/wp-api.js @@ -1234,7 +1234,9 @@ }, // Specify the model that this collection contains. - model: loadingObjects.models[ modelClassName ], + model: function( attrs, options ) { + return new loadingObjects.models[ modelClassName ]( attrs, options ); + }, // Include a reference to the original class name. name: collectionClassName, @@ -1257,7 +1259,9 @@ url: routeModel.get( 'apiRoot' ) + routeModel.get( 'versionString' ) + routeName, // Specify the model that this collection contains. - model: loadingObjects.models[ modelClassName ], + model: function( attrs, options ) { + return new loadingObjects.models[ modelClassName ]( attrs, options ); + }, // Include a reference to the original class name. name: collectionClassName,