Forums / Developer / Code problem when fetching objects

Code problem when fetching objects

Author Message

Eirik Alfstad Johansen

Friday 19 November 2004 7:00:30 am

Hi guys,

The following code is supposed to fetch a list of objects where the object attribute value of the class attribute id 505 contains the value "ARBEID". However, instead, it fetches all the objects under the $parentNodeID. Are there any obvious syntax errors in the code?

$fetchObject = new eZContentFunctionCollection;
$products = $fetchObject->fetchObjectTree(
$parentNodeID, array(), false, 
false, 4, 'le', false, array( 'or', array( 505, '=', 'ARBEID' )), 
false, false, false, false, null, true);

Thanks in advance !

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Lazaro Ferreira

Friday 19 November 2004 8:43:31 am

Hi,

Change change attributefilter code to :

array( array( 505, '=', 'ARBEID' ) )

it should work

Lazaro
http://www.mzbusiness.com

Eirik Alfstad Johansen

Friday 19 November 2004 9:35:08 am

Nope, that didn't do the trick. Any other ideas?

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Lazaro Ferreira

Friday 19 November 2004 10:09:24 am

Hi,

I just can confirm you that a code like this works perfectly here :


$attribute_filter = array( array( 330,'=', $myvalue ) );   
							
$matchingObjectList = array();

$matchingObjectList =& eZContentFunctionCollection::fetchObjectTree( 
                                                                     $parentNodeID, $sortBy, $offset, $limit, 
                                                                     $depth, $depthOperator,
                               		                       $classID, $attribute_filter, 
							     $extended_attribute_filter, $class_filter_type, 
							     $class_filter_array,
                                    $groupBy, $mainNodeOnly, $asObject );

Of course every variable was properly set before

The only difference we got is that we use php

::

operator instead of creating a new instance of eZContentFunctionCollection, but this couldn't be a problem

Lazaro
http://www.mzbusiness.com

Eirik Alfstad Johansen

Saturday 20 November 2004 2:53:33 am

Hi Lazaro,

I dont think the 'or' part of the attribute filter is the problem as I use it in several other places of the script where it works as supposed to. Any other ideas?

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Eirik Alfstad Johansen

Monday 22 November 2004 6:44:55 am

Bump. Anyone?

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Kåre Køhler Høvik

Monday 22 November 2004 7:46:09 am

This looks wrong.

array( 'or', array( 505, '=', 'ARBEID' ))

You need 2 parameters after the 'or'.

You can also try to turn on debug output and SQL output. Try to locate the SQL statement this query generates, and paste it here.

Kåre Høvik

Lazaro Ferreira

Monday 22 November 2004 9:09:24 am

Hi

I'm agree with Kare

I had though in the same way when I suggest you to change your filter to

array( array(505,'=','ARBEID') )

, because this way your are implicitly using

AND

logic in your SQL query, instead

OR

logic.

In any case it seems to me that you should use AND logic instead OR logic to get what you want

Lazaro
http://www.mzbusiness.com

Eirik Alfstad Johansen

Monday 22 November 2004 10:35:10 am

Thanks for your helpful advice, guys. After some extensive bug hunting and printing SQL queries, it turns out that the problem wasn't in the code I posted, but rather in the custom datatype upon which the attribute I was searching was built. The datatype missed the following method:

function &sortKeyType()
    {
        return 'string';
    }

...causing the SQL query to search the sort_key_int field of the db table instead og sort_key_string.

Not an easy one to spot, that one. Thanks again for all your help!

PS. Kåre: You mentioned turning SQL output on? Is there an INI switch for this? If so, where is it located?

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Ole Morten Halvorsen

Monday 22 November 2004 11:14:11 am

Eirik,

file: settings/site.ini

[DatabaseSettings]
SQLOutput=enabled

Ole M.

Senior Software Engineer - Vision with Technology

http://www.visionwt.com
http://www.omh.cc
http://www.twitter.com/omh

eZ Certified Developer
http://ez.no/certification/verify/358441
http://ez.no/certification/verify/272578