Skip to content

Unique validation fails when validating a subterm of another term #1616

@cincauhangus

Description

@cincauhangus

I've encountered an issue when using unique Validator. I'm using Laravel v5.2 & laravel-mongo v3.2.3. The following is the steps to reproduce:

Existing records in database:

{'name': "Banking"}
{'name': "Finance and Banking"}

Validation rule used:

$this->rules = ['name' => 'unique:brands,name,NULL,_id,deleted_at,NULL'];

Data to be validated before inserting:

{'name': "Finance"}

Expected validation result should be pass, but instead it failed. Upon further checking, the following line looks for unique value using case-insensitive regex, thus returning values that matches Finance, in this case Finance and Banking.

https://github.com/jenssegers/laravel-mongodb/blob/bc78c7575b879351eedc4a57b5ac0410ee765b51/src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php#L20

Upon changing to $this->table($collection)->where($column, $value); will fix the problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs investigationNeed investigation about bugs described in issuebug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions