ssign placeholders per model for dirty fields that have values and NULL for dirty fields that don't. foreach ( $models as $model ) { $placeholder = []; foreach ( $dirty_column_names as $dirty_field ) { $placeholder[] = ( $model->orm->dirty_fields[ $dirty_field ] === null ) ? 'NULL' : '%s'; } $placeholders = \implode( ', ', $placeholder ); $total_placeholders .= "({$placeholders}),"; } $query[] = \rtrim( $total_placeholders, ',' ); return \implode( ' ', $query ); } /** * Deletes this record from the database. * * @return string The delete query. * * @throws \Exception Primary key ID contains null value(s). * @throws \Exception Primary key ID missing from row or is null. */ public function delete() { $query = [ 'DELETE FROM', $this->quote_identifier( $this->table_name ), $this->add_id_column_conditions() ]; return self::execute( \implode( ' ', $query ), \is_array( $this->id( true ) ) ? \array_values( $this->id( true ) ) : [ $this->id( true ) ] ); } /** * Deletes many records from the database. * * @return bool|int Response of wpdb::query. */ public function delete_many() { // Build and return the full DELETE statement by concatenating // the results of calling each separate builder method. $query = $this->join_if_not_empty( ' ', [ 'DELETE FROM', $this->quote_identifier( $this->table_name ), $this->build_where(), ] ); return self::execute( $query, $this->values ); } /* * --- ArrayAccess --- */ /** * Checks whether the data has the key. * * @param mixed $offset Key. * * @return bool Whether the data has the key. */ #[ReturnTypeWillChange] public function offsetExists( $offset ) { return \array_key_exists( $offset, $this->data ); } /** * Retrieves the value of the key. * * @param mixed $offset Key. * * @return array|mixed|null The value. */ #[ReturnTypeWillChange] public function offsetGet( $offset ) { return $this->get( $offset ); } /** * Sets the value of the key. * * @param string|int $offset Key. * @param mixed $value Value. */ #[ReturnTypeWillChange] public function offsetSet( $offset, $value ) { if ( \is_null( $offset ) ) { return; } $this->set( $offset, $value ); } /** * Removes the given key from the data. * * @param mixed $offset Key. */ #[ReturnTypeWillChange] public function offsetUnset( $offset ) { unset( $this->data[ $offset ] ); unset( $this->dirty_fields[ $offset ] ); } /* * --- MAGIC METHODS --- */ /** * Handles magic get via offset. * * @param mixed $key Key. * * @return array|mixed|null The value in the offset. */ public function __get( $key ) { return $this->offsetGet( $key ); } /** * Handles magic set via offset. * * @param string|int $key Key. * @param mixed $value Value. */ public function __set( $key, $value ) { $this->offsetSet( $key, $value ); } /** * Handles magic unset via offset. * * @param mixed $key Key. */ public function __unset( $key ) { $this->offsetUnset( $key ); } /** * Handles magic isset via offset. * * @param mixed $key Key. * * @return bool Whether the offset has the key. */ public function __isset( $key ) { return $this->offsetExists( $key ); } }