Support

Home Forums Event Espresso Premium delete all associated datetime objects using EEM_Datetime::delete_related

delete all associated datetime objects using EEM_Datetime::delete_related

Posted: April 10, 2021 at 4:28 pm

Viewing 2 reply threads


make_webmaster

April 10, 2021 at 4:28 pm

Using the model/class behavior of EE, I want to delete all associated datetime objects, tickets and prices.

I found delete_related here – https://github.com/eventespresso/event-espresso-core/blob/master/docs/G–Model-System/using-ee4-model-objects.md

and attempted both of the below
EE_Datetime::delete_related(array( array( ‘Event.EVT_ID’ => ‘3764’ )));
EEM_Datetime::delete_related(array( array( ‘Event.EVT_ID’ => ‘3764’ )));

They through the following error:
Deprecated: Non-static method EE_Base_Class::delete_related() should not be called statically

Any help with the correct use of this function would be great


Tony

  • Support Staff

April 12, 2021 at 6:34 am

Hi there,

When you do something like this:

EE_Datetime::delete_related()

The :: means you are trying to call a ‘static’ method on a class. The above calls the delete_related() method on the EE_Datetime class, but that method isn’t static. A ‘static method’ is a method (function) that is available on a class without the need to have an instance of that class.

To confuse things a little more, it is common to see methods that relate to a class written as above even though they are not static, why? Because it’s an easier way to show that method relates to the class (Yeah, I know it throws a spanner in the works).

So for your specific example you would use something like:

$datetime = EEM_Datetime::instance()->get_by_by_ID( {datetime_id} );
$datetime->delete_related(array( array( 'Event.EVT_ID' => '3764' )));

I’m not sure the above does what you are expect though, you may want to look at how the _permanently_delete_event() method removes the related data from the event, HERE.

Notice how it uses the EVent Object and pulls the related details from there.


make_webmaster

April 12, 2021 at 8:44 am

Thank you Tony! That is exactly what I was looking for!

Viewing 2 reply threads

The support post ‘delete all associated datetime objects using EEM_Datetime::delete_related’ 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