Forums / Developer / fetch sort_by conditional

fetch sort_by conditional

Author Message

Lachy Laycock

Saturday 01 November 2003 4:28:11 am

Hi all,
I am trying to fetch data with a conditional in it, but can't work out the sort_by syntax...

I am trying to do this:

Fetch all children of a certain node of a certain class where the value of item.data_map.year.data_int > 2002.

Any ideas?

Thanks,
Lachy

Paul Forsyth

Saturday 01 November 2003 4:39:50 am

Have a read of this doco:

http://ez.no/developer/ez_publish_3/documentation/development/libraries/ez_template/operators/data_fetch

paul

Lachy Laycock

Saturday 01 November 2003 5:06:09 am

Thanks for the reply.

I actually looked at that page before posting. I am afraid, it didn't clear up my confusion:

Here is what I am trying to do:
Fetch all children of node 47 of class 19 where the value of item.data_map.year.data_int > 2002.

fetch( content, list, hash(
parent_node_id, 47,
limit, 3,
sort_by, array( priority, false() ),
class_filter_type, include,
class_filter_array, array( 19 )
attribute_filter( 19, '>', 2002) ) )}

now I assume the attribute_filter() syntax is incorrect, but I am not sure how to get the fetch to match against values in the children nodes...

Any pointers would be much appreciated.

Thanks,
Lachy

Paul Forsyth

Saturday 01 November 2003 5:30:22 am

The problem is likely with your use of the class attribute id. You have:

attribute_filter( 19, '>', 2002)

where it is seems 19 is the class id. but if you look at the doco again this parameter needs to the class attribute id.

What you need to do is look at your class again in the admin and identify the id number for your 'year' attribute. Put this number in your fetch and see if this works.

Btw, do you have debug on? It may be reporting this error.

paul

Lachy Laycock

Saturday 01 November 2003 8:26:08 am

Quite rightly, the docos specify the class attribute id.

In my admin section it reports that my class attribute id is 171:
Year (Integer) (id:171)

so, i modified to suit this:
{let news_list=fetch( content, list, hash(
parent_node_id, 47,
sort_by, array( array( published, false() ) ),
attribute_filter, array('or', array(171, '>=', 2003) ) ) )}

and presto it works! My syntax and my id were wrong.

What makes little sense to me is the need for the "array('or', ...)" part in the syntax, but it works and for the moment that is good enough.

Thanks for the help again!

Paul Forsyth

Sunday 02 November 2003 5:07:22 am

Glad it worked :)

The use of 'array' is just a way of passing the variables from the template language to the underlying php. i think by using an array all the parameters are passed in with a single variable. this helps keep the api interface a little simpler.

paul