Welcome, Guest
Username: Password: Remember me

TOPIC: ORM union

ORM union 02 Feb 2017 20:28 #14972

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
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'
The administrator has disabled public write access.

ORM union 03 Feb 2017 12:03 #14975

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
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 administrator has disabled public write access.
The following user(s) said Thank You: vlemos

ORM union 03 Feb 2017 12:25 #14976

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
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
Last Edit: 03 Feb 2017 12:26 by admin.
The administrator has disabled public write access.
The following user(s) said Thank You: vlemos
Time to create page: 0.085 seconds

Get Started