Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

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

  • vlemos
  • vlemos's Avatar Topic Author
  • Online
  • Elite Member
  • Elite Member
  • Posts: 295
  • Thank you received: 41
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 `vs4go_users` AS _user_id_
				  ON _user_id_.id = a.user_id
		   LEFT JOIN `vs4go_user_usergroup_map` AS _user_usergroup_map_id_
				  ON _user_usergroup_map_id_.user_id = a.user_id
		   LEFT JOIN `vs4go_usergroups` AS _usergroup_id_
				  ON _usergroup_id_.id = _user_usergroup_map_id_.group_id
		   LEFT JOIN `vs4go_cook_usergroups` AS _usergroups_id_
				  ON _usergroups_id_.user_id = a.id
		   LEFT JOIN `vs4go_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

Please Log in or Create an account to join the conversation.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
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
The following user(s) said Thank You: vlemos

Please Log in or Create an account to join the conversation.

Last edit: by admin.
  • Page:
  • 1
Time to create page: 0.073 seconds
  I still don't believe he can really be human to do all this ! From all of the forums that I've ever participated in this is certainly the one that most encapsulates the feeling of being truly open source where everyone's opinions and contributions can and will shape the development of the service! It's truly awesome! Hope you enjoy cooking and look forward to reading and contributing to any of the editorial work that you proposed too!! Thanks
Gez (audibleid - JED)

Get Started