Skip to content

Validations of subproperties in Loopback Model #300

@bartolkaruza

Description

@bartolkaruza

I'm having trouble understanding why index and validation is not working on my Model defined programatically. Below is the setup of a simple shopping cart Model, for which I need to use a custom id which is not at the root level of the model.

var defaultSettings = {idInjection:false, strict:true};

var CartEntityModel = {
    'products':{type:[Product], required:false}, // Product is defined elsewhere
    'cartId':{type:String, required:true, index:true, generated:true}
}

var CartEntity = ds.define('cartEntity', CartEntityModel, defaultSettings);

var cartProperties = {
    '_entity': {type:CartEntity, required:true}
}

app.model('cart', {
    properties: cartProperties,
    options: defaultSettings,
    dataSource: 'mongodb'
});

This generates an id field at the root of the 'cart' and only validates that the _entity field is not empty. No other validation at lower levels takes place and the index property seems to be entirely ignored. What am I doing wrong here?

The structure is more complex than absolutely necessary because I need to match an existing data structure, which always has '_entity' at the root and the id's at deeper levels.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions