mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 23:56:36 +00:00
#216 - ENH: Add Model.Finder deleteById(id) method
This commit is contained in:
@@ -248,10 +248,12 @@ public abstract class Model {
|
||||
return new Finder<I, T>(server, idType, type);
|
||||
}
|
||||
|
||||
// Does not exist yet but I think should
|
||||
// public void deleteById(I id) {
|
||||
// return db().deleteById(type, id);
|
||||
// }
|
||||
/**
|
||||
* Delete a bean by Id.
|
||||
*/
|
||||
public void deleteById(I id) {
|
||||
db().delete(type, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all entities of the given type.
|
||||
|
||||
@@ -455,7 +455,11 @@ public final class DefaultPersister implements Persister {
|
||||
// delete the bean(s)
|
||||
SqlUpdate deleteById = descriptor.deleteById(id, idList);
|
||||
if (t.isLogSummary()) {
|
||||
t.logSummary("-- Deleting " + descriptor.getName() + " Ids" + idList);
|
||||
if (idList != null) {
|
||||
t.logSummary("-- Deleting " + descriptor.getName() + " Ids: " + idList);
|
||||
} else {
|
||||
t.logSummary("-- Deleting " + descriptor.getName() + " Id: " + id);
|
||||
}
|
||||
}
|
||||
|
||||
// use Id's to update L2 cache rather than Bulk table event
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.avaje.tests.delete;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.tests.model.onetoone.Account;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class TestDeleteByIdUsingModel extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Account account = new Account();
|
||||
account.setName("GoingToDeleteThis");
|
||||
account.save();
|
||||
|
||||
Account account1 = Account.find.byId(account.getId());
|
||||
assertEquals(account.getName(), account1.getName());
|
||||
|
||||
Account.find.deleteById(account.getId());
|
||||
|
||||
Account account2 = Account.find.byId(account.getId());
|
||||
assertNull(account2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user