Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Marten.Testing/Documents/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public enum Colors

public class Target
{
public record Nested(Target[] Targets);

public Nested NestedObject { get; set; }
private static readonly Random _random = new Random(67);

private static readonly string[] _strings =
Expand Down Expand Up @@ -64,7 +67,7 @@ public static Target Random(bool deep = false, bool includeFSharpUnionTypes = fa
target.Number = _random.Next();
target.AnotherNumber = _random.Next();
target.OtherGuid = Guid.NewGuid();

target.Flag = _random.Next(0, 10) > 5;

target.Float = float.Parse(_random.NextDouble().ToString());
Expand Down Expand Up @@ -120,6 +123,7 @@ public static Target Random(bool deep = false, bool includeFSharpUnionTypes = fa

if (deep)
{
target.NestedObject = new Nested(new []{Random(), Random()});
target.Inner = Random();

var number = _random.Next(1, 10);
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Schema/SQL/mt_jsonb_patch.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ BEGIN

patch_expression = null;
IF (patch->>'type') IN ('remove', 'append_if_not_exists', 'insert_if_not_exists') AND (patch->>'expression') IS NOT NULL THEN
patch_expression = jsonb_path_query_array(retval->(patch->>'path'), (patch->>'expression')::jsonpath);
patch_expression = jsonb_path_query_array(retval #> patch_path, (patch->>'expression')::jsonpath);
END IF;

CASE patch->>'type'
Expand Down
19 changes: 19 additions & 0 deletions src/PatchingTests/Patching/patching_api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,25 @@ public async Task remove_complex_elements_by_predicate()

#endregion

[Fact]
public async Task remove_complex_nested_elements_by_predicate(){
var target = Target.Random(true);
var random = new Random();
var initiallength = target.NestedObject.Targets.Length;
var randomitem = target.NestedObject.Targets[random.Next(0, initiallength)];

theSession.Store(target);
await theSession.SaveChangesAsync();

theSession.Patch<Target>(target.Id).Remove(x => x.NestedObject.Targets, x => x.Id == randomitem.Id);
await theSession.SaveChangesAsync();

await using var query = theStore.QuerySession();
var target2 = query.Load<Target>(target.Id);
target2.NestedObject.Targets.Length.ShouldBe(initiallength - 1);
target2.NestedObject.Targets.ShouldNotContain(x => x.Id == randomitem.Id);
}

[Fact]
public async Task throw_exception_if_a_method_call_is_used_for_remove_complex_element_by_predicate()
{
Expand Down