Forums / General / attribute_filter: needs more explanation

attribute_filter: needs more explanation

Author Message

Thomas Brandl

Friday 19 September 2003 7:01:09 am

Hi guys,

Scenario:
I have a fetch(content, list,..) which correctly gets all the objects I want it to get, now I want to limit the result with attribute_filter.

First problem: I do not get it work with one argument only, like:
attribute_filter, array( 159, '=', 'aValue' )

it doesn't seem to be the correct syntax, any other is not intuitive for me and there's no example with only one argument, so I use the example I found:

attribute_filter,
array( 'or', array( 159, '=', 'aValue'' ), array( 156, '=', 'foobar' ))

attribute_id 156 is valid, but does o.c not contain foobar, it's an 'or' combination, so it shouldn't matter.

Now, take for granted, there is a attribute_id 159, it's a text line datatype, and be asured, there is an (published) object with a corresponding value 'aValue'!

I don't get it to fetch anything, no errors, no output.

I don't know where to start to look for the problem! Did I misunderstand anything?

Thanks very much for help!
t

Tom Couwberghs

Tuesday 23 September 2003 5:17:27 am

I had some problems with it too. But after some trial and error I found how it works.

If you want to filter only on one parameter just leave out the third parameter. It would look like this: array('or', array(156, '=', 'foobar'))

If you don't see anything appearing that could be lots of things. My advice -- first try a fetch without attribute_filter and if that's working -> start filtering.

Also check if you clear the cache entirely. There is a little mistake of the eZ crew in the clear cache script in 3.2 stable. Consult this thread: http://ez.no/developer/ez_publish_3/forum/install_configuration/cache_wont_clear_in_32

HTH

--
T

Thomas Brandl

Tuesday 23 September 2003 6:20:54 am

Hi Tom,

fetch without filtering is no problem, did not get any further.

Do you have a working example for me, maybe the problem lies somewhere else and I'm to blind to see!?

Thomas Brandl

Tuesday 23 September 2003 7:23:19 am

found this:
eZ is trying to find the value i'm looking for in ezcontentobject_attribute.sort_key_string:
... ( a0.sort_key_string = 'aValue' ) ...

This field is empty for all my records!

Besides, I don't understand it: If I'd decide to filter on some other attribute tomorrow, how should this value find its way into sort_key_String or sort_key_int?? Should't the field to search in depend solely on the datatype used for the attribute in question - data_text, data_int or data_float?

Thanks for enlightment
t

Tom Couwberghs

Wednesday 24 September 2003 12:51:14 am

The following code works for me:

{let folder_list=fetch( content, list, hash( parent_node_id, 2, sort_by, array( array( priority ) ),
attribute_filter, array('or', array(152, '=', '0')))) }

{section name=Folder loop=$folder_list}
<td class="topmenu">
<a href={concat( "/content/view/full/", $Folder:item.node_id, "/" )|ezurl}>{$Folder:item.name|wash}</a>
</td>
{/section}
{/let}

2 remarks:

About the no errors thing -> Is debug enabled on your site? If not switch it to enabled in site.ini

Are you using version 3.2 stable, in previous versions there was a bug that generated a wrong query?
HTH

--
Tom