Filtering list values by several relationship entities

13 Oct '14, 02:19 PM
2,509 Views
No Forum Badges

Hello,

I'm having an issue with the list component and the relationship role condition. Basicly, I have two entities A and B that have an N to N relationship. What I want to do is to have a list of entities of A and filter them with a multi-selection field, which has all the different entities of B in it. The list should then only show the instances of A which are connected to the selected instances of B. Right now it's somewhat working in the sense that it only shows entities that have ANY of the selected instances of B, but I'd like it to show only the ones that have all of them.

Is there a way to achieve this?

Thanks for any help you can provide!

 
x 0
Follow
Answer Answer at this question and get points!
Forum Starter - Level 3

Hi Ville, 

the "Relationship Role Condition" provides only 2 "Predicate" option: "In" and "Not In". So, you cannot achieve your goal using it, because the "In" predicate will always return all the elements in B having a relationship with any selected element in your multi selection field.

In order to solve your problem I think there are 2 possible solution:

 

  • Using a "Script" Component:

you can add in your model a Script Component and write a custom SQL query in order to get exactly the desired result from your entities A and B.
You can find more details about how to use a Script Compontent at the following link: 

http://www.webratio.com/learn/learningobject/using-the-script-component
  • Using an operation chain and a volatile entity for filtering your data

For example, let's consider the case where you have the entities "Product" and "Colors" connected by a N-N relationship. In this case you should build a model such as the following one:

https://drive.google.com/file/d/0Bwj4WXZL5K0Vc0Voc0VhTkdUTHc/view?usp=sharing

As you can see in the attached image, the model these steps:

  1. The user selects one or more colors in the multiselection field (2) and press the Button corresponding to the navigation link
  2. The operations no.3 and no.4 copy all the existing products in the volatile entity
  3. The loop component receives from the Form component the array of the selected colors. 
  4. The selector no.6 get all the products currently recorded in the volatile entity and pass their key to the selector no.7
  5. The selector no.7 computes (starting from the original entity of product) which of the products in the volatile entity are related to the colors selection (the colors selection is passed as input via the data flow starting from the Loop Component)
  6. Then the Delete component (no.8) deletes all the products in the volatile that are not included in the set resulting from the selector no.7
  7. In this way, while looping, you will clean the product list from the elements not having a relationship with the selected colors.
  8. Finally the selector no.9 simply return all the remaining elements in the volatile entity of products and pass the resulting filtered key set to the List Component in the page.
  9. In this way the list will show the expected result

Remeber that the "Create" Operation automatically create the oid key, so in order to avoid problems, we use the product_oid attribute in the volatile entity to store the original key for each product in the Product entity.

If you need to learn how to use the loop content, please refer to this online lesson: 

http://www.webratio.com/learn/learningobject/looping-branching

Let me know if this helps.

Regards

 
x 0
Answer at this question and get points!