Skip to content
Snippets Groups Projects
Commit 0d713eeb authored by Josh Pollock's avatar Josh Pollock
Browse files

delete entry values by entry id

parent 2374ba3c
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
namespace calderawp\CalderaFormsQuery\Tests\Integration\Delete;
use calderawp\CalderaFormsQuery\Delete\Entry;
use calderawp\CalderaFormsQuery\Delete\EntryValues;
use calderawp\CalderaFormsQuery\Tests\Integration\IntegrationTestCase;
use calderawp\CalderaFormsQuery\Tests\Traits\CanCreateEntryWithEmailField;
......@@ -79,4 +80,39 @@ class EntryValuesTest extends IntegrationTestCase
}
/**
*
*
* @covers EntryValues::deleteByEntryIds()
*/
public function testDeleteByEntryIds()
{
$entryIdOne = $this->createEntryWithMockFormAndGetEntryId();
$entryIdTwo = $this->createEntryWithMockFormAndGetEntryId();
$entryIdThree = $this->createEntryWithMockFormAndGetEntryId();
//Delete entry one and three
$sql = $this
->entryValuesDeleteGeneratorFactory()
->deleteByEntryIds([$entryIdOne,$entryIdThree])
->getPreparedSql();
$this->queryWithWPDB($sql);
//No results for entry One
$entryValuesQueryGenerator = $this->entryValuesGeneratorFactory();
$entryValuesQueryGenerator->queryByEntryId($entryIdOne);
$sql = $entryValuesQueryGenerator->getPreparedSql();
$results = $this->queryWithWPDB($sql);
$this->assertSame( 0, count( $results ) );
//Results for entry Two
$entryValuesQueryGenerator = $this->entryValuesGeneratorFactory();
$entryValuesQueryGenerator->queryByEntryId($entryIdTwo);
$sql = $entryValuesQueryGenerator->getPreparedSql();
$results = $this->queryWithWPDB($sql);
$this->assertTrue( 0 < count( $results ) );
}
}
\ No newline at end of file
......@@ -22,6 +22,18 @@ class EntryValues extends DeleteQueryBuilder
return $this;
}
/**
* Delete a collection of entry values that are for a a set of entries.
*
* @param array $entryIds
* @return $this
*/
public function deleteByEntryIds(array $entryIds)
{
return $this->in($entryIds,'entry_id');
}
/**
* Delete all field values with a value
*
......
......@@ -160,17 +160,18 @@ abstract class QueryBuilder implements CreatesSqlQueries
}
/**
* Add a WHERE IN()
* Add a WHERE IN() $column
*
* @param array $entryIds
* @param array $entryIds Entries to search in
* @param string $column Column name. Default is 'id'.
* @return $this
*/
protected function in(array $entryIds)
protected function in(array $entryIds, $column = 'id')
{
$this
->getCurrentQuery()
->where()
->in('id', $entryIds);
->in($column, $entryIds);
return $this;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment