Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
orderBy value in related table

 

 


rjbathgate
User

Nov 14, 2011, 7:03 PM

Post #1 of 2 (201 views)
Shortcut
orderBy value in related table Can't Post

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!


Jason
Staff / Moderator


Nov 14, 2011, 8:51 PM

Post #2 of 2 (199 views)
Shortcut
Re: [rjbathgate] orderBy value in related table [In reply to] Can't Post

Hi,

Yes, you can do this by using the leftJoin option in getRecords. For example:


Code
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 - Programmer 
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/