Zeka

Arrays and joinFields options in find method

Recommended Posts

Hi. 

I'm trying to tune my searches, so I'm playing with 'loadOptions' and 'joinFields'. I successfully decrease the amount of PDO queries, buy joining not complex field types. But when I join field types as Images, SelectOptions ( all where multiple values are returned ) and then access them, they contain only the first array value. 

$products = $pages->find("template=product, (category=$page), (categories=$page), sort=-stock, sort=title, ", ['loadOptions' => [
	'joinFields' => [
		'page_title',
		'images', // has multiple values
		'labels', // has multiple values
		'price',
		'unit',
		'special_price'
	]]]);

foreach ($products as $p) {
	$p->labels <--- contain only first value 
}

Is it normal behavior? If so, can somebody provide some good read about it.

Thanks!

 

Share this post


Link to post
Share on other sites
3 hours ago, Zeka said:

But when I join field types as Images, SelectOptions ( all where multiple values are returned ) and then access them, they contain only the first array value.

A couple of things Ryan has said:

Quote

Be careful with multi-value fields that offer autojoin capability (page references and images, for example). Because MySQL limits the combined length of multiple values returned from a group in 1 query, autojoin will fail on multi-value fields that contain lots of values (combined length exceeding 1024 characters). If you experience strange behavior from a multi-value field that has autojoin ON, turn it OFF. If you want to play it safe, then don't use autojoin on multi-value fields like page references and images.

https://processwire.com/talk/topic/26-what-is-the-autojoin-feature-in-the-fields-editor-and-how-do-i-use-it/

Quote

Using autojoin on FieldtypeMulti fields (like pages, files, images, comments, etc.) is a tricky matter because the primary page load query is designed to execute with 1 fetch with no data repetition. That ensures the fastest possible performance. Fields with multiple entries (FieldtypeMulti) are not well suited to being retrieved in 1 fetch. However, ProcessWire can still do it using a MySQL GROUP_CONCAT function to bundle the multiple entires into a string suitable for that 1 fetch. The problem is that MySQL has a byte limit on how much it will GROUP_CONCAT (it's a MySQL setting that we can't count on). As a result, autojoin is okay to use on simple multi-entry fields like Page relations that don't have hundreds of entries–that's because it's just a bunch of integers. But it's not well suited for more complex fields like images that might have long descriptions. As a result, I don't recommend using it with file/image fieldtypes.

https://processwire.com/talk/topic/613-underlying-workings-of-autojoin/?do=findComment&amp;comment=4948

 

  • Like 3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.