Search in sources :

Example 16 with Product

use of com.orm.androrm.impl.Product in project androrm by androrm.

the class ManyToManyFieldTest method testReset.

public void testReset() {
    Product p1 = new Product();
    p1.setName("test1");
    p1.save(getContext());
    Product p2 = new Product();
    p2.setName("test2");
    p2.save(getContext());
    Brand b = new Brand();
    b.setName("Copcal");
    b.save(getContext());
    Supplier s = new Supplier();
    s.setName("ACME");
    s.setBrand(b);
    s.addProducts(Arrays.asList(new Product[] { p1, p2 }));
    s.save(getContext());
    assertEquals(2, s.getProducts(getContext()).count());
    s.delete(getContext());
    assertEquals(0, s.getProducts(getContext()).count());
}
Also used : Brand(com.orm.androrm.impl.Brand) Product(com.orm.androrm.impl.Product) Supplier(com.orm.androrm.impl.Supplier)

Example 17 with Product

use of com.orm.androrm.impl.Product in project androrm by androrm.

the class ManyToManyFieldTest method testCount.

public void testCount() {
    Product p1 = new Product();
    p1.setName("test1");
    p1.save(getContext());
    Product p2 = new Product();
    p2.setName("test2");
    p2.save(getContext());
    Brand b = new Brand();
    b.setName("Copcal");
    b.save(getContext());
    Supplier s = new Supplier();
    s.setName("ACME");
    s.setBrand(b);
    s.addProducts(Arrays.asList(new Product[] { p1, p2 }));
    assertEquals(0, s.productCount(getContext()));
    s.save(getContext());
    s = Supplier.objects(getContext()).get(s.getId());
    assertEquals(2, s.productCount(getContext()));
}
Also used : Brand(com.orm.androrm.impl.Brand) Product(com.orm.androrm.impl.Product) Supplier(com.orm.androrm.impl.Supplier)

Aggregations

Product (com.orm.androrm.impl.Product)17 Brand (com.orm.androrm.impl.Brand)7 Supplier (com.orm.androrm.impl.Supplier)6 Filter (com.orm.androrm.Filter)5 ForeignKeyField (com.orm.androrm.field.ForeignKeyField)5 Branch (com.orm.androrm.impl.Branch)4 ArrayList (java.util.ArrayList)4 Rule (com.orm.androrm.Rule)2 TableDefinition (com.orm.androrm.TableDefinition)2 InStatement (com.orm.androrm.statement.InStatement)2 LikeStatement (com.orm.androrm.statement.LikeStatement)2 Statement (com.orm.androrm.statement.Statement)2 DatabaseAdapter (com.orm.androrm.DatabaseAdapter)1 Model (com.orm.androrm.Model)1