WordPress.org

Make WordPress Core

Changeset 39604


Ignore:
Timestamp:
12/15/2016 01:01:26 PM (3 years ago)
Author:
adamsilverstein
Message:

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.
Merges [39603] to the 4.7 branch.
Fixes #39070.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-includes/js/wp-api.js

    r39344 r39604  
    12351235
    12361236                        // Specify the model that this collection contains.
    1237                         model: loadingObjects.models[ modelClassName ],
     1237                        model: function( attrs, options ) {
     1238                            return new loadingObjects.models[ modelClassName ]( attrs, options );
     1239                        },
    12381240
    12391241                        // Include a reference to the original class name.
     
    12581260
    12591261                        // Specify the model that this collection contains.
    1260                         model: loadingObjects.models[ modelClassName ],
     1262                        model: function( attrs, options ) {
     1263                            return new loadingObjects.models[ modelClassName ]( attrs, options );
     1264                        },
    12611265
    12621266                        // Include a reference to the original class name.
Note: See TracChangeset for help on using the changeset viewer.