Welcome, Guest
Username: Password: Remember me

TOPIC: ORM Distinct and table aliases

ORM Distinct and table aliases 27 Feb 2017 14:50 #15014

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
Hello Admin

I have 2 questions

1. How does Cook ORM handle select distinct from table?

2. I have "groups" and "usergroups" tables as part of my component which I link to within a query. I also link to the native Joomla tables in that same query but Cook ORM seems not to understand that these two sets of tables are really very different. I am not sure how to ask it to make the aliases unique without changing my table names.

Thanks
vlemos


The final query should look like this:
	SELECT DISTINCT
		   a.id,
		   a.user_id,
		   _user_id_.name                   AS `_user_id_name`,
		   _user_usergroup_map_id_.group_id AS `_user_usergroup_map_id_group_id`,
		   _usergroup_id_.title             AS `_usergroup_id_title`,
		   a.created_by,
		   a.published
	FROM   #__cook_users AS a
		   LEFT JOIN `#__users` AS _user_id_
				  ON _user_id_.id = a.user_id
		   LEFT JOIN `#__user_usergroup_map` AS _user_usergroup_map_id_
				  ON _user_usergroup_map_id_.user_id = a.user_id
		   LEFT JOIN `#__usergroups` AS _usergroup_id_
				  ON _usergroup_id_.id = _user_usergroup_map_id_.group_id
		   LEFT JOIN `#__cook_usergroups` AS _usergroups_id_
				  ON _usergroups_id_.user_id = a.id
		   LEFT JOIN `#__cook_groups` AS _group_id_
				  ON _group_id_.id = _usergroups_id_.group_id
	WHERE  ( a.published = 0
			  OR a.published = 1
			  OR a.published IS NULL )
		   AND _usergroup_id_.title = 'Mrs.'
		   AND _group_id_.level >= 30
		   AND a.company_id = 1
	ORDER  BY a.user_id ASC
The administrator has disabled public write access.

ORM Distinct and table aliases 27 Feb 2017 16:30 #15015

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
1. Select distinct is not supported. You can fork the ORM class to custom it.
Create another function named distinct(), or add some parameters in the config of select(). As you prefer

2. For the select with aliases, yes it is possible:
see : www.j-cook.pro/index.php/o/orm-system#select
Section "Alias"
Coding is now a piece of cake
Last Edit: 27 Feb 2017 16:30 by admin.
The administrator has disabled public write access.
The following user(s) said Thank You: vlemos
Time to create page: 0.102 seconds

Get Started