Skip to content

Fix for select fields #45

@iz-iznogood

Description

@iz-iznogood

When using select on a breeze query, the result returns also the sequelize models (especially if we expand into some navigation property) and this creates serialization problems

I managed to overcome this issue by using the Model.get({ plain: true }) which returns simple javascript objects without the sequelize models and also with nested sub-objects / sub-arrays which IMHO maps better to what the client might expect

Proposed method change in SequelizeQuery.js

private _reshapeSelectResults(sqResults: CountModel | Model[]) {
    const options = {
        plain: true
    };
    if (this.entityQuery.inlineCountEnabled) {
        return {
            results: (sqResults as CountModel).rows.map(x => x.get(options)),
            inlineCount: (sqResults as CountModel).count
        };
    } else {
        return (sqResults as Model[]).map(x => x.get(options));
    }
}

It is tested and works well but it changes the semantics because now for nested properties the system returns

{
    "foo.bar": 1
}

and my code returns

{
    foo: {
         bar: 1
    }
}

But this allows us to handle nested arrays which did not work before

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions