[#2817] allowed 0 as RelationOptions.MinSelect value
This commit is contained in:
		
							parent
							
								
									2cb642bbf7
								
							
						
					
					
						commit
						7297f55ca4
					
				|  | @ -73,6 +73,8 @@ | |||
| 
 | ||||
| - Soft-deprecated `security.NewToken()` in favor of `security.NewJWT()`. | ||||
| 
 | ||||
| - Allowed `0` as `RelationOptions.MinSelect` value to avoid the ambiguity between 0 and non-filled input value ([#2817](https://github.com/pocketbase/pocketbase/discussions/2817)). | ||||
| 
 | ||||
| 
 | ||||
| ## v0.16.6 | ||||
| 
 | ||||
|  |  | |||
|  | @ -653,7 +653,7 @@ func (o RelationOptions) Validate() error { | |||
| 
 | ||||
| 	return validation.ValidateStruct(&o, | ||||
| 		validation.Field(&o.CollectionId, validation.Required), | ||||
| 		validation.Field(&o.MinSelect, validation.NilOrNotEmpty, validation.Min(1)), | ||||
| 		validation.Field(&o.MinSelect, validation.Min(0)), | ||||
| 		validation.Field(&o.MaxSelect, validation.NilOrNotEmpty, validation.Min(minVal)), | ||||
| 	) | ||||
| } | ||||
|  |  | |||
|  | @ -2112,6 +2112,22 @@ func TestRelationOptionsValidate(t *testing.T) { | |||
| 			}, | ||||
| 			[]string{"collectionId"}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			"MinSelect < 0", | ||||
| 			schema.RelationOptions{ | ||||
| 				CollectionId: "abc", | ||||
| 				MinSelect:    types.Pointer(-1), | ||||
| 			}, | ||||
| 			[]string{"minSelect"}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			"MinSelect >= 0", | ||||
| 			schema.RelationOptions{ | ||||
| 				CollectionId: "abc", | ||||
| 				MinSelect:    types.Pointer(0), | ||||
| 			}, | ||||
| 			[]string{}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			"MaxSelect <= 0", | ||||
| 			schema.RelationOptions{ | ||||
|  | @ -2128,6 +2144,42 @@ func TestRelationOptionsValidate(t *testing.T) { | |||
| 			}, | ||||
| 			[]string{}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			"MinSelect < MaxSelect", | ||||
| 			schema.RelationOptions{ | ||||
| 				CollectionId: "abc", | ||||
| 				MinSelect:    nil, | ||||
| 				MaxSelect:    types.Pointer(1), | ||||
| 			}, | ||||
| 			[]string{}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			"MinSelect = MaxSelect (non-zero)", | ||||
| 			schema.RelationOptions{ | ||||
| 				CollectionId: "abc", | ||||
| 				MinSelect:    types.Pointer(1), | ||||
| 				MaxSelect:    types.Pointer(1), | ||||
| 			}, | ||||
| 			[]string{}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			"MinSelect = MaxSelect (both zero)", | ||||
| 			schema.RelationOptions{ | ||||
| 				CollectionId: "abc", | ||||
| 				MinSelect:    types.Pointer(0), | ||||
| 				MaxSelect:    types.Pointer(0), | ||||
| 			}, | ||||
| 			[]string{"maxSelect"}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			"MinSelect > MaxSelect", | ||||
| 			schema.RelationOptions{ | ||||
| 				CollectionId: "abc", | ||||
| 				MinSelect:    types.Pointer(2), | ||||
| 				MaxSelect:    types.Pointer(1), | ||||
| 			}, | ||||
| 			[]string{"maxSelect"}, | ||||
| 		}, | ||||
| 	} | ||||
| 
 | ||||
| 	checkFieldOptionsScenarios(t, scenarios) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue