Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0] Add missing case CUSTOM_OBJECT to statement #212

Open
wants to merge 1 commit into
base: 2.0-dev
Choose a base branch
from

Conversation

fastslack
Copy link

Summary of Changes

Just adding a missing statement for custom

Testing Instructions

This issue can be reproduced calling a loadObjectList method using the second parameter for a (custom?) class.

For example

		$db = $this->getDbo();

		$query = $db->getQuery(true)
			->select(
				$db->quoteName(
					[
						'menu.id',
						'menu.menutype',
						'menu.title',
						'menu.alias',
						'menu.note',
						'menu.link',
						'menu.type',
						'menu.level',
						'menu.language',
						'menu.browserNav',
						'menu.access',
						'menu.params',
						'menu.home',
						'menu.img',
						'menu.template_style_id',
						'menu.component_id',
						'menu.parent_id'
					]
				)
			)
			->select(
				$db->quoteName(
					[
						'menu.path',
						'extensions.element',
						'menu_types.title',
						'pwtsitemap_menu_types.custom_title'
					],
					[
						'route',
						'component',
						'menuTitle',
						'customTitle'
					]
				)
			)
			->from($db->quoteName('#__menu', 'menu'))
			->leftJoin(
				$db->quoteName('#__extensions', 'extensions')
				. ' ON ' . $db->quoteName('menu.component_id') . ' = ' . $db->quoteName('extensions.extension_id')
			)
			->leftJoin(
				$db->quoteName('#__menu_types', 'menu_types')
				. ' ON ' . $db->quoteName('menu_types.menutype') . ' = ' . $db->quoteName('menu.menutype')
			)
			->leftJoin(
				$db->quoteName('#__pwtsitemap_menu_types', 'pwtsitemap_menu_types')
				. ' ON ' . $db->quoteName('pwtsitemap_menu_types.menu_types_id') . ' = ' . $db->quoteName('menu_types.id')
			)
			->where($db->quoteName('menu.published') . ' = 1')
			->where($db->quoteName('menu.parent_id') . ' > 0')
			->where($db->quoteName('menu.client_id') . ' = 0')
			->order($db->quoteName('pwtsitemap_menu_types.ordering') . ' ASC')
			->order($db->quoteName('menu.lft'));

		// Set the query
		$db->setQuery($query);

		$this->items = $db->loadObjectList('id', MenuItem::class);

I tested this using Joomla! 4 on github repository and the latest 4.0-dev branch

Documentation Changes Required

@fastslack fastslack changed the title Add missing case CUSTOM_OBJECT to statement [2.0] Add missing case CUSTOM_OBJECT to statement Jul 10, 2020
@mbabker
Copy link
Contributor

mbabker commented Jul 10, 2020

This is by design. The PHP level database code does not really work efficiently, or consistently, with objects. Trying to instantiate a custom object through a database API yields unpredictable results, you are better off using a data mapping layer to convert the database result set into the object type you are trying to represent (see examples in core for dealing with the MenuItem class in particular).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants