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

TOPIC:

ORM union 02 Feb 2017 20:28 #14972

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

Please help? How do I create the query below in the new orm framework; Is it possible?

Thanks
v
Select
  a.id,
  a.name,
  a.published,
  a.created_by
From
  #__table a
Where
  a.created_by = 12
union All
Select
  a.id,
  a.name,
  a.published,
  a.created_by
From
  #__table a
where
  a.type <> 'bi'
And
  a.type <> 'pv'

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

ORM union 03 Feb 2017 12:03 #14975

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
The union is not supported yet.

If you use it only once, do it manually.
If your component will require unions SQL, you can create your own.

As usual, the ORM class is forkable, so just create a new directive 'union', wich recieve a sub ORM config (such as relations)

TODO :
- Create a new entry in the set() function (in the switch)
- Create a new directive union (recieve a sub ORM full description)

Some directives recieve a name. (filters / relations / access ...).
You can avoid this name for union and create a nameless directive (such as : select / context / order / id)

The name is used in case you are instancing more than one union in the same query (is it usefull ?). Do the simpiest for the moment

Hope it helps. I think it is not a big deal, and for you a nice learning exercise.
I estimate approximatively 15 lines max at the correct place, will you be able to relieve the challenge ?
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.

ORM union 03 Feb 2017 12:25 #14976

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
I often start to code basing on the desired call.
In this case, the caller should say something like that :
$this->orm(array(
	// Base query (corresponding to your example)
	// Normally called by your context call
	'select' => array('id','name','published','created_by'),

	// Force the Filter value
	'filter' => array(
		'created_by' => array(
			'value' => 12
		)
	),




	// UNION : Simple version (nameless)
	'union' => array(

		// TODO : Missing in ORM
		'from' => 'a',

		'filter' => array(
			'type' => array(
				// TODO : Missing in ORM
				'sql' => "a.type <> 'bi' AND a.type <> 'pv'"
			)
		)

	),



	// UNION : Namespaced version
	'union' => array(
		'myUnion1' => array(
			'from' => 'a',
			'filter' => array(
				'type' => array(
					'sql' => "a.type <> 'bi' AND a.type <> 'pv'"
				)
			)
		)
	)

));

As you can see, it is missing some parts in ORM before to achieve this union:
- Create the @sql parameter of the filter directive for overriding the query condition.
- Handle 'from' directly in the union directive function, or create a new 'from' directive in ORM

Got it ?
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.059 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