orderBy value in related table
2 posts by 2 authors in: Forums > CMS Builder
Last Post: November 14, 2011 (RSS)
Howdy,
Say I have table "products", and each record has a field "category", which is linked (num value) to table "categories".
In table 'categories', each category has a value "Featured" checkbox.
Is there an easy / built in way I can use this value in the related table to order the products table...
I could do it by running both tables into a new array and restoring, but wondered if there was a simply way I could do it in the products list viewer "orderBy" statement....
Cheers!
Say I have table "products", and each record has a field "category", which is linked (num value) to table "categories".
In table 'categories', each category has a value "Featured" checkbox.
Is there an easy / built in way I can use this value in the related table to order the products table...
I could do it by running both tables into a new array and restoring, but wondered if there was a simply way I could do it in the products list viewer "orderBy" statement....
Cheers!
Re: [rjbathgate] orderBy value in related table
By Jason - November 14, 2011
Hi,
Yes, you can do this by using the leftJoin option in getRecords. For example:
This returns the records in "products" sorted so that the products with a category where the featured checkbox is checked appear first.
Hope this helps
Yes, you can do this by using the leftJoin option in getRecords. For example:
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'allowSearch' => false,
'leftJoin' => array('categories' => 'category'),
'orderBy' => 'categories.featured DESC',
));
This returns the records in "products" sorted so that the products with a category where the featured checkbox is checked appear first.
Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/