-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.6] Ignore a given model during a unique check. #23524
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know, it was wrongly added. Sorry for that. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,15 @@ | |
namespace Illuminate\Tests\Validation; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class ValidationUniqueRuleTest extends TestCase | ||
{ | ||
public function testItCorrectlyFormatsAStringVersionOfTheRule() | ||
{ | ||
$rule = new \Illuminate\Validation\Rules\Unique('table'); | ||
$rule->where('foo', 'bar'); | ||
$this->assertEquals('unique:table,NULL,NULL,id,foo,bar', (string) $rule); | ||
$this->assertEquals('unique:table,NULL,NULL,NULL,foo,bar', (string) $rule); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes me uncomfortable having to change an old test to add this feature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need the default value for the idColumn that's why i had to change the test here, because we really don't need the 'id' since the ignore is NULL. but I can revert this change and still the feature will pass. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK please don't change that test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, Sorry for that 👍 |
||
|
||
$rule = new \Illuminate\Validation\Rules\Unique('table', 'column'); | ||
$rule->ignore('Taylor, Otwell', 'id_column'); | ||
|
@@ -21,5 +22,23 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule() | |
$rule->ignore(null, 'id_column'); | ||
$rule->where('foo', 'bar'); | ||
$this->assertEquals('unique:table,column,NULL,id_column,foo,bar', (string) $rule); | ||
|
||
$model = new EloquentModelStub(['id_column' => 1]); | ||
|
||
$rule = new \Illuminate\Validation\Rules\Unique('table', 'column'); | ||
$rule->ignore($model); | ||
$rule->where('foo', 'bar'); | ||
$this->assertEquals('unique:table,column,"1",id_column,foo,bar', (string) $rule); | ||
|
||
$rule = new \Illuminate\Validation\Rules\Unique('table', 'column'); | ||
$rule->ignore($model, 'id_column'); | ||
$rule->where('foo', 'bar'); | ||
$this->assertEquals('unique:table,column,"1",id_column,foo,bar', (string) $rule); | ||
} | ||
} | ||
|
||
class EloquentModelStub extends Model | ||
{ | ||
protected $primaryKey = 'id_column'; | ||
protected $guarded = []; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we removed the default value for the protected $idColumn; and the __toString() need string conversion for the variables