Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep subModelTypes with custom subModelTypeAttribute #545

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matghaleb
Copy link

subModel's instantiation is failing when using 2 or more levels of subModelTypes and custom subModelTypeAttribute.

You can see this issue from this jsfiddle and compare the results with my PR from here.

Here is the new test I joined to the PR. Please tell me if you need more information

test( "Object building based on type in a custom field, when using explicit collections" , function() {
            var scope = {};
            Backbone.Relational.store.addModelScope( scope );

            scope.Mammal = Animal.extend({
                subModelTypes: {
                    'primate': 'Primate',
                    'carnivore': 'Carnivore'
                }
            });
            scope.Primate = scope.Mammal.extend();
            scope.Carnivore = scope.Mammal.extend({
                subModelTypeAttribute: 'family',
                subModelTypes: {
                    'feline': 'Feline',
                    'canid': 'Canid'
                }
            });

            scope.Feline = scope.Carnivore.extend();
            scope.Canid = scope.Carnivore.extend();

            var MammalCollection = AnimalCollection.extend({
                model: scope.Mammal
            });

            var mammals = new MammalCollection( [
                { id: 5, species: 'chimp', type: 'primate' },
                { id: 6, species: 'panther', type: 'carnivore' },
                { id: 9, species: 'coyote', type: 'carnivore', family: 'canid' },
                { id: 10, species: 'leopard', type: 'carnivore', family: 'feline'}
            ]);

            ok( mammals.at( 0 ) instanceof scope.Primate );
            ok( mammals.at( 1 ) instanceof scope.Carnivore );
            ok( mammals.at( 2 ) instanceof scope.Canid );
            ok( mammals.at( 3 ) instanceof scope.Feline );
        });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant