Skip to content

Commit 5d1559a

Browse files
committed
fix: can search for numeric strings in a collection's child string prop
fixes #12
1 parent 0729831 commit 5d1559a

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

QueryKit.IntegrationTests/Tests/DatabaseFilteringTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,37 @@ public async Task can_filter_by_string_for_collection()
7171
recipes[0].Id.Should().Be(fakeRecipeOne.Id);
7272
}
7373

74+
[Fact]
75+
public async Task can_filter_by_numeric_string_for_collection()
76+
{
77+
// Arrange
78+
var testingServiceScope = new TestingServiceScope();
79+
var faker = new Faker();
80+
var fakeIngredientOne = new FakeIngredientBuilder()
81+
.WithName("abc123")
82+
.Build();
83+
var fakeRecipeOne = new FakeRecipeBuilder().Build();
84+
fakeRecipeOne.AddIngredient(fakeIngredientOne);
85+
86+
var fakeIngredientTwo = new FakeIngredientBuilder()
87+
.WithName(faker.Lorem.Sentence())
88+
.Build();
89+
var fakeRecipeTwo = new FakeRecipeBuilder().Build();
90+
fakeRecipeTwo.AddIngredient(fakeIngredientTwo);
91+
await testingServiceScope.InsertAsync(fakeRecipeOne, fakeRecipeTwo);
92+
93+
var input = $"""Ingredients.Name @=* "123" """;
94+
95+
// Act
96+
var queryableRecipes = testingServiceScope.DbContext().Recipes;
97+
var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input);
98+
var recipes = await appliedQueryable.ToListAsync();
99+
100+
// Assert
101+
recipes.Count.Should().Be(1);
102+
recipes[0].Id.Should().Be(fakeRecipeOne.Id);
103+
}
104+
74105
[Fact]
75106
public async Task can_filter_by_string_for_collection_with_count()
76107
{

QueryKit/FilterParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private static Expression CreateRightExprFromType(Type leftExprType, string righ
171171
var targetType = leftExprType;
172172
if (isEnumerable)
173173
{
174-
if (int.TryParse(right, out var intVal))
174+
if (int.TryParse(right, out var intVal) && targetType.GetGenericArguments().All(arg => arg != typeof(string)))
175175
{
176176
// supports collection count
177177
return Expression.Constant(intVal, typeof(int));

0 commit comments

Comments
 (0)