Forums

Search all the attribute values of all the elements

shiluba 02 Dec, 2019
Hi,
I am trying to get a search form to work on a sub-model.
The main table called "elements" is loaded by the main model called "elem".
The sub-table called "attributes" is loaded by the sub-model called "attr". This model is set with the Relation : "Multiple matching records, foreign key in this table." The searched keywords are to be found into the "value" column of the "attributes" table.
When I try this condition (under the Where conditions of "elem") ...
attr.value/LIKE:%{data:keywords}%
... I get this error : 1054 Unknown column 'attr.value' in 'where clause'.
Does anyone know if what I'm trying is doable with CCv6 ?
Thanks in advance for your advices🙂
healyhatman 03 Dec, 2019
I don't think what you're trying to do is doable in CCv6 or even just in MySQL. You have to include every column.
shiluba 04 Dec, 2019
Answer
I managed to do it by turning the "attr" sub-model into the main model of another Read data called "search_attributes" and loaded before the main Read data.
​
"search_attributes" is set with ...
- Select type : Return an array of key/values ...
- No page limit
- Where condition : attr.value ... LIKE ... %{data:keywords}% ... Null value : Continue
- Fields to retrieve : elem_id (= foreign key matching with the id columns of the "elements" table)

​
Then, into the main Read data, I added this where condition :
elem.id ... IN ... {var:search_attributes} ... Null value : continue
And that's it. The main Read data gets filtered according to the search results based on all the values of the "attributes" table.
This topic is locked and no more replies can be posted.