Support

Home Forums Event Espresso Premium Query question

Query question

Posted: November 27, 2018 at 2:48 pm

Viewing 3 reply threads


ARAGATO

November 27, 2018 at 2:48 pm

This is my registration table in SQL
http://uploads.aragato-server.net/screenshots/20181127d5d139dfe4.png

This is my query
$this->registrations = EEM_Registration::instance()->get_all(
array(array(
‘STS_ID’ => ‘RAP’, //Registration Approved, Space Reserved
‘OR’ => array( ‘REG_final_price’ => 0,
‘REG_paid’ => array( ‘<‘, ‘REG_final_price*’ ) ) ) ) );

It should return at least 5 datasets based from the SQL data.
However, it returns only the free course, but does not return all the other courses that should be selected. The issue seems to lie within the second part of the OR (All registrations that have REG_paid smaller than REG_final_price).

What am I missing?


ARAGATO

November 27, 2018 at 3:24 pm

After thinking about it, the issue is probably the ‘REG_final_price*’ which is seen by the query as a string and not as the respective column/field.

How do I reference that field?

Also, I have used the EEM_Extra_Meta a bit. For example, I process some registrations and add to each processed regisration an extra meta field ‘processed’ = true.

How can I implement the exta meta into a registration query. For instance, get all registrations where processed is true?


Tony

  • Support Staff

November 29, 2018 at 10:08 am

After thinking about it, the issue is probably the ‘REG_final_price*’ which is seen by the query as a string and not as the respective column/field.

That’s correct, and admittedly, the documentation for this is a little hard to find.

Its actually really simple to do, you just need an additional parameter:

$this->registrations = EEM_Registration::instance()->get_all(
	array(
		array(
			'STS_ID' => 'RAP', //Registration Approved, Space Reserved
			'OR' => array( 
				'REG_final_price' => 0,	
				'REG_paid' => array( '<', 'REG_final_price', true )
			)
		)
	) 
);

array( '<', 'REG_final_price', true ) tells the model that the value passed is a field name.

How can I implement the exta meta into a registration query. For instance, get all registrations where processed is true?

Same as with most models, you add the model and field, so something like this:

'Extra_Meta.EXM_key' => 'processed',
'Extra_Meta.EXM_value' => true

Meaning your code ends up like this:

$this->registrations = EEM_Registration::instance()->get_all(
	array(
		array(
			'STS_ID' => 'RAP', //Registration Approved, Space Reserved
			'OR' => array( 
				'REG_final_price' => 0,	
				'REG_paid' => array( '<', 'REG_final_price', true )
			),
			'Extra_Meta.EXM_key' => 'processed',
			'Extra_Meta.EXM_value' => true
		)
	) 
);


ARAGATO

December 2, 2018 at 4:22 am

awesome, thanks.

Viewing 3 reply threads

The support post ‘Query question’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso