0

I'd like to use the relationship filter to filter for a tags. This works fine when I pass a text string and it can search the EntityTitle, but I'd like to pass an entity_id to the filter.

I noticed in the details of the query results that the relationship filter has a "CompareAttribute=EntityTitle". Is there a way to edit that to make it EntityID?

Thanks.

Mike
  • 107
  • 7

2 Answers2

0

At the moment filtering by a different property in related items could only be done in code. Heres' how

  1. create your visual query as you would, with the only "mistake" being the wrong field
  2. in your razor template, access the Query with var q = App.Query["queryname"];
  3. then before you get the data, change the CompareAttribute. This will take a bit of fiddling about, because you have to cast the q from before to a IDataTarget and navigate up the query-tree like var relFilter = q.In["Default"].Source, then cast that again to the right type, and then change the relFilter.CompareAttribute = "Country";

...something like that :)

Afterwards you can access the query results with a foreach(var x in AsDynamic(q["Default"])) {...}

iJungleBoy
  • 5,325
  • 1
  • 9
  • 21
0

I've tried this where I wanted some locations grouped by region, So I did:

  • region 1
    • address 1
    • address 2
  • region 2
    • address 3
    • address 4

So basically it should do the same except it would query by region. So this is what I came up with:

@{
    var someAddresses = App.Query["FilterAddresses"]["ListContent"];
    someAddresses.Filter = region.RegionName;
    Data.In.Add("someAddresses", someAddresses["Default"]);
}
@foreach (var pc in AsDynamic(someAddresses.List)) {
    <li>@pc.Naam</li>
}

However it says:

CS1061: ToSic.Eav.DataSources.IDataStream does not contain a definition for Filter.

So should it be something else?

Tim Diekmann
  • 7,755
  • 11
  • 41
  • 69
MBouwman
  • 45
  • 8