Using a Aggregate Model field as a condition to another model

  • 2
  • Question
  • Updated 2 years ago
  • Answered
I have two aggregate models, which I use to populate two filters in a table. I would like it to be posible for a user to set one filter and for the values that appear in the next one to be limited by it (ie for there to be a filter hierarchy between them)

I tried adding a condition on 'ImpactTopic' using a Field from another Model from 'RealtedPracticesImpactArea', but unfortunately I get this error

1. A Skuid Model, 'ImpactTopic', has a Field from another model Condition referencing a field, 'Goal__r.Related_Practices_Impact_Area__r.Name', that is not found in the source model, 'RealtedPracticesImpactArea'. Please add the field to the source model, change the condition to reference another field that is in the source model, or remove this condition.

because 'RealtedPracticesImpactArea' is an aggregate model, I cannot select that field (the fields dialogue disapears, it is replaced by the Grouping option.

A) Is there a way to use field from another model to achieve a dependent filter when the source is an aggregate model?
b) Is there another way to achieve this filter hierarchy?

Thanks!
Photo of Santiago Perez

Santiago Perez

  • 362 Points 250 badge 2x thumb

Posted 2 years ago

  • 2
Photo of Stephen Sells

Stephen Sells, Official Rep

  • 16,856 Points 10k badge 2x thumb
Have you come across this tutorial?

http://help.skuid.com/m/models-conditions-filters/l/204980-use-a-snippet-as-a-filter-item-source-to-...

I'm trying to come up with a declarative way that doesn't use code. If a method becomes known to me, I'll post it here.
Photo of Stephen Sells

Stephen Sells, Official Rep

  • 16,856 Points 10k badge 2x thumb
This is a declarative way to create a filter hierarchy from two aggregate models.

This is the finished result shown sequentially for clarity:



Notice that when a Country Code is selected, the options in the Genre Filter are updated to reflect the potential genres only available in the selected country code.

We’ll need two conditions in the table’s model (Artist) to filter based on the aggregate models. How to properly set these up has been defined in official skuid tutorials.



One aggregate model aggregates country codes and the other genres. The top screenshot is the country code model and the leader/parent in the filter hierarchy. Genre is the bottom screenshot. Notice that the Genre aggregate needs a Multiple Specified Value Operator in order to accept multiple genres to pass through.



Here we have our two filters on the Artist model (main table model from above). Left is parent / Country Code. Right is child / Genre.
A few points to notice:
Their “Model Condition to Affect” correspond to the conditions created in the table’s conditions (Artist).
Their “Source: Rows in a Model” correspond to the groupings done in the aggregate model.



Finally, we need to have the following set up in our Artist model’s Action Framework.


This is where things get tricky. You’ll notice that there are 6 different actions here, but it’s essentially just 3 actions repeated twice.
These actions are triggered when the model’s conditions are changed - when the Country Code Filter is applied.
At that moment, we activate the condition set in the Genre Aggregate model

The Country Code filter changes the Artist model’s condition. By changing that, the Aggregate model for genre is being activated and set. Then both models are refreshed to reflect the update.

It might seem redundant, but it needs to be done twice. If you really want to know why, ask and I’ll tell you... but it’s a wee complicated.