nov 28, 2022 5:26 AM
Hi,
I struggling with this seemingly simple script:
{% set rows = hubdb_table_rows(XXXX) %}
{% set test = hubdb_table_row(XXXX,YYYY) %}
{% set queryValue = test.title %}
{% set match = rows|selectattr('title','eq', queryValue ) %}
{{ match }}
renders: []
So I create a collection by getting the table rows.
I get a single row in the test variable, from the same table.
I take the value of one property of that row
I use that value to filter the rows and find that one row. In theory this should return at least the one row that I fetched in 'test', but it returns nothing.
This is not my real use case, just an illustration of what I think is a bug. In my real case I'm not setting the queryValue to a value that I fetched from the row. It is a different one and I want to find the rows that match. This is just an illustration that selectattr seems to break when the last argument is a variable.
nov 28, 2022 6:14 AM
Hi PDeT,
test variable stored the set of records. you need to print test variable. so you will see, that's not a title but it's a rows
{# get all hubDB records at rows #}
{% set rows = hubdb_table_rows(5630042,93304468552) %}
{% set test = hubdb_table_rows(5630042,93304468553) %}
{% set queryValue = test[0].name %} {# OUTPUT Pratik #}
{# test variable get set of row. so you need to select specific row. test object stored [{},{},{}] of records. #}
{% set match = rows|selectattr('name','eq', queryValue ) %}
<pre>
queryValue - {{ queryValue }}
match - {{ match }}
</pre>
nov 28, 2022 3:14 PM
hi @2CUBE-Studio ,
In my example, the test is filled from hubdb_table_row which is a different function from your example hubdb_table_rows.
Anyway, a lot more debugging later, it appears to be a data issue (and a hubl issue). For some records taking the title and then running a selectattr with that title returns no results, for others, it worked. So depending on the value of YYYY I had sometimes normal results and sometimes no result.
This is a bug imho, although a different one then I initially thought. If you take the value of a property of a row as the value for a filter on that same property, you should at least get the row from which it was taken as a result. An empty result is broken math 😉
Probably there happens some sanitation of some sort on the value, which then causes it not to match anymore with the original value, resulting in an empty match collection. I haven't found the possible cause for this. At first I thought it could be the space in the string, but another record which also had a space in the title field worked fine.
I'll go back to my client and pressure them a little harder to not try to match on titles but on id's, which I hope will have fewer problems.
Kind regards,
Pieter