New topic Closed topic
avatar image
1
Deduplicate collection in Betty
By Created , last editted

Hey all,


I'm trying to populate and deduplicate a collection at an action event. The collection is populated using an other collection with a has many relation to an a second model with a belongs to, to a third collection.


See the image below of how I've tried to accomplish this and the results.

When encapsulating the expression in the uniq() function, the results are the same.


Any idea how the deduplicate the result?


BTW: The last approach​ results in a collection, in a collection (var:main_collection). Like this:


After creating an extra collection variable and use var:main_collection​[0] in the expression, you can use this in a template and use the uniq filter of Liquid, you do get the desired result. Like this:


But for performance reasons and in cases you are not using a template/Liquid, I like to know an approach for just in Betty.


Hey all,


I'm trying to populate and deduplicate a collection at an action event. The collection is populated using an other collection with a has many relation to an a second model with a belongs to, to a third collection.


See the image below of how I've tried to accomplish this and the results.

When encapsulating the expression in the uniq() function, the results are the same.


Any idea how the deduplicate the result?


BTW: The last approach​ results in a collection, in a collection (var:main_collection). Like this:


After creating an extra collection variable and use var:main_collection​[0] in the expression, you can use this in a template and use the uniq filter of Liquid, you do get the desired result. Like this:


But for performance reasons and in cases you are not using a template/Liquid, I like to know an approach for just in Betty.

Answers
Sort by:

This topic is closed.