filterByCollectionAttribute in the Collection object is not working??

Permalink
I have created a custom attribute called PageGroup and i am trying to get a list of pages that has this attribute set to 'main':

Loader::model('page_list');
$pl = new PageList(); $pl->filterByCollectionAttribute('LanguageGroup', 'main', '=');

$pages = $pl->get(100, 0);

But i get the following MySql error:
mysql error: [1054: Unknown column 'ak_collection_attribute' in 'where clause'] ...

If you look at the MySql statement Generated, i notice that its trying to compare a column name call ak_collection_attribute while in fact it should look at ak_LanguageGroup.

Is this a knowned issue?

Thank you,

Frank

Francois
 
glockops replied on at Permalink Reply
glockops
Are you certain that your collection attribute's handle is LanguageGroup and not something like language_group?

Doublecheck the naming there. Make sure you're referencing the handle and not the name of the attribute. I could be wrong, but it seems that your code can't find the attribute handle so it's defaulting to the database column name 'ak_collection_name'.

Relevant API Information:
filterByCollectionAttribute (string $handle, string $value, [ $comparison = '='])
Francois replied on at Permalink Reply
Francois
I looked in the CollectionSearchIndexAttributes table and the column name is really ak_LanguageGroup

So was i right to pass 'LanguageGroup' as the first parameter?
goldfish replied on at Permalink Reply
goldfish
I'm having a similar issue. Am I doing something wrong? I have a custom attribute with handle ViewQuality and one value is Oceanfront. I want to display a list with only pages with Oceanfront views. I tried
Loader::model('page_list');
$pl = new PageList();
$pl->filterByParentID($parentID);
$pl->setItemsPerPage(25);
$pl->filterByPageAttribute('ViewQuality','Oceanfront','=');
$pages = $pl->getPage();
foreach($pages as $p) { ?>
   <a href="<?=Loader::helper('navigation')->getLinkToCollection($p)?>">
   <?=$p->getCollectionName()?></a><br/>
<? } ?>

and got the following mysql errror - I never see the value I'm filtering on: 'Oceanfront' anywhere in the query

mysql error: [1054: Unknown column 'ak_page_attribute' in 'where clause'] in EXECUTE("select p1.cID, pt.ctHandle from Pages p1 left join Pages p2 on (p1.cPointerID = p2.cID) left join PageTypes pt on (pt.ctID = (if (p2.cID is null, p1.ctID, p2.cID))) left join PagePaths on (PagePaths.cID = p1.cID and PagePaths.ppIsCanonical = 1) left join PageSearchIndex psi on (psi.cID = if(p2.cID is null, p1.cID, p2.cID)) inner join CollectionVersions cv on (cv.cID = if(p2.cID is null, p1.cID, p2.cID) and cvID = (select max(cvID) from CollectionVersions where cID = cv.cID)) inner join Collections c on (c.cID = if(p2.cID is null, p1.cID, p2.cID)) left join CollectionSearchIndexAttributes on (CollectionSearchIndexAttributes.cID = if (p2.cID is null, p1.cID, p2.cID)) where 1=1 and p1.cParentID = '97' and cvIsApproved = '1' and (p1.cIsTemplate = 0 or p2.cIsTemplate = 0) and ak_page_attribute = 'ViewQuality' limit 0,25 ")

Thanks!
synlag replied on at Permalink Reply
synlag
i think the handle must be lowercased. i'm not 100% sure, but i think i stumbled about this some time ago.
johndorsay replied on at Permalink Best Answer Reply
johndorsay
I've had this issue as well. It seems to work properly if you set your attribute handles like so. this_is_my_handle. No spaces no uppercases.
goldfish replied on at Permalink Reply
goldfish
That was it. thanks_so_much!
Francois replied on at Permalink Reply
Francois
So i guess its just like when you give a name to your custom blocks, you can't put uppercase letters.

Thanks guys!
Francois replied on at Permalink Reply
Francois
I know its been a while but i wanted to get rid of my hack and use this in another project and it still does'nt work if you put lowecase attribute name...