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

TOPIC:

[ADDED] Exploded prepareQuery() - ORM reduced 05 Jan 2017 14:18 #14913

  • vlemos
  • vlemos's Avatar Topic Author
  • Away
  • Elite Member
  • Elite Member
  • Posts: 295
  • Thank you received: 41
Will there be a way to have the builder generate the original [non-ORM] prepareQuery with its filters?
	/**
	* Preparation of the list query.
	*
	* @access	protected
	* @param	object	&$query	returns a filled query object.
	*
	* @return	void
	*/
	protected function prepareQuery(&$query)
	{

		$acl = TestHelper::getActions();

		//FROM : Main table
		$query->from('#__users AS a');



		//IMPORTANT REQUIRED FIELDS
		$this->addSelect(	'a.id');


		switch($this->getState('context', 'all'))
		{

			case 'all':
				//SELECT : raw complete query without joins
				$this->addSelect('a.*');

				// Disable the pagination
				$this->setState('list.limit', null);
				$this->setState('list.start', null);
				break;
		}

		//FILTER - Access for : Root table


		//WHERE - FILTER : created_by
		if($filter_created_by = $this->getState('filter.created_by'))
		{
			if ($filter_created_by == 'auto'){
				$this->addWhere('a.created_by = ' . (int)JFactory::getUser()->get('id'));
			}
			else 
			if ($filter_created_by > 0){
				$this->addWhere("a.created_by = " . (int)$filter_created_by);
			}
		}


		//WHERE - FILTER : modified_by
		if($filter_modified_by = $this->getState('filter.modified_by'))
		{
			if ($filter_modified_by == 'auto'){
				$this->addWhere('a.modified_by = ' . (int)JFactory::getUser()->get('id'));
			}
			else 
			if ($filter_modified_by > 0){
				$this->addWhere("a.modified_by = " . (int)$filter_modified_by);
			}
		}


		//WHERE - FILTER : user_id
		if($filter_user_id_user_id = $this->getState('filter.user_id_user_id'))
		{
			$this->addJoin("`#__test_users` AS _user_id_ ON _user_id_.id = a.user_id", 'LEFT');
			if ($filter_user_id_user_id == 'auto'){
				$this->addWhere('_user_id_.user_id = ' . (int)JFactory::getUser()->get('id'));
			}
			else 
			if ($filter_user_id_user_id > 0){
				$this->addWhere("_user_id_.user_id = " . (int)$filter_user_id_user_id);
			}
		}


		//WHERE - FILTER : user_id
		if($filter_user_id = $this->getState('filter.user_id'))
		{
			if ($filter_user_id == 'auto'){
				$this->addWhere('a.user_id = ' . (int)JFactory::getUser()->get('id'));
			}
			else 
			if ($filter_user_id > 0){
				$this->addWhere("a.user_id = " . (int)$filter_user_id);
			}
		}


		// Apply all SQL directives to the query
		$this->applySqlStates($query);
	}

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

[ADDED] Exploded prepareQuery() - ORM reduced 05 Jan 2017 14:43 #14914

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
For simple filters, yes, but for complex such as lists, accesses (+propagation), pivots... it will still use the ORM because it has always been such.

If you look at your previous components the ORM is there already for those special ones. (The functions are still there at the moment)
I wrote ORM for simplificating the fields and for other coming features.
I will not remove this layer even with an option. Simply exploding the construction with non-ORM statements, and only for the simple ones.
Believe me, I cannot put all the model behaviors repeated in every prepareQuery() function. It would be insane.

ORM is not a complex framework it is simply a very light constructor for avoiding repetition of code, nothing more.
I don't want to do the revolution with :
$city = new City();
This would be a complex useless layer for us. Not needed.

So the option I will propose to you is prepareQuery() exploded. So it will be more easy for you to see the SQL query construction.

BTW, when you want to dump you SQL query, use the queryDump() function. (ORM class)
It is quite usefull for working with your queries.
Coding is now a piece of cake

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

[ADDED] Exploded prepareQuery() - ORM reduced 09 Jan 2017 13:01 #14927

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
This monday, you can enjoy the ORM option for building.

In the component configuration, you will find "SQL Queries" parameter.
Choose "Exploded", and tell me if this fits to your needs.
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.

[ADDED] Exploded prepareQuery() - ORM reduced 09 Jan 2017 16:30 #14929

  • vlemos
  • vlemos's Avatar Topic Author
  • Away
  • Elite Member
  • Elite Member
  • Posts: 295
  • Thank you received: 41
Thanks so very much Jocelyn, I believe this offers me the best of both worlds. I can play and get comfortable with ORM and still meet the delivery/maintenance schedules of current "legacy" projects; being able to benefit from v3.1 updates and modifications is a plus. :woohoo:

I hope I am not alone and that it will help others who maybe in a similar predicament.

Warm regards
v

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

[ADDED] Exploded prepareQuery() - ORM reduced 10 Jan 2017 17:02 #14932

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
This is an excellent feature! Great thing to mix ORM and custom queries ...

So, in a case 'layout.xxxx' context, that mix ORM and SQL query, how to use the queryDump() function ?
the code below just give the FROM query and nothing else :
                $this->orm->queryDump($query);

                // Apply all SQL directives to the query
                $this->applySqlStates($query);
stdClass Object
(
    [FROM] => #__jbreeding_pedigrees AS a
)

Please, I need the right syntax to debug the full query ...

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

Last edit: by liubov.

[ADDED] Exploded prepareQuery() - ORM reduced 10 Jan 2017 19:23 #14934

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
AFTER
$this->applySqlStates($query);
Coding is now a piece of cake

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

[ADDED] Exploded prepareQuery() - ORM reduced 10 Jan 2017 22:31 #14935

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
Whaoo ! Excellent !!!

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

  • Page:
  • 1
Time to create page: 0.072 seconds

I'm playing around with the new mvc and the FORK feature is FANTASTIC!!! it's saving me a lot of time! you are doing a very good job!!

Tomaselli (Forum)  

Get Started