Skip to content

Unique Name Validation using multiple columns #90

@vaidehi-imedia

Description

@vaidehi-imedia

I'm using bookshelf.js instead of knex and I want to check for unique using name and id attribute of the table.

How can I pass req.params in my custom function that checks for unique name in table?

Below is my code:

function assertEditRoleName(val, params, context) {
        return Role
            .forge()
            .where('id', '<>', 2)
            .where('name', '=', val)
            .where('is_deleted', '=', 0)
            .fetchAll()
            .then(function (existing) {
                if (existing.models.length > 0) {
                    throw new Error('Duplicated role name');
                }
            }).catch(function (err) {
                console.log(err);
            });
    }

In above code, i'm getting only name in val and I want to pass id also from my request body.

I have checked #26
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions