Search in sources :

Example 6 with Supplier

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

the class FieldResulutionTest method testManyToManyFieldResolutionLastField.

public void testManyToManyFieldResolutionLastField() {
    List<Supplier> suppliers = new ArrayList<Supplier>();
    suppliers.add(mS1);
    Filter filter = new Filter();
    filter.in("mBranches__mSuppliers", suppliers);
    QuerySet<Product> products = Product.objects(getContext()).filter(filter);
    assertEquals(1, products.count());
    assertTrue(products.contains(mP1));
    suppliers.clear();
    filter = new Filter();
    filter.in("mBranches__mSuppliers", suppliers);
    products = Product.objects(getContext()).filter(filter);
    assertEquals(0, products.count());
}
Also used : Filter(com.orm.androrm.Filter) ArrayList(java.util.ArrayList) Product(com.orm.androrm.impl.Product) Supplier(com.orm.androrm.impl.Supplier)

Example 7 with Supplier

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

the class FieldResulutionTest method testOneToManyResolutionLastField.

public void testOneToManyResolutionLastField() {
    List<Branch> branches = new ArrayList<Branch>();
    branches.add(mB1);
    branches.add(mB2);
    Filter filter = new Filter();
    filter.in("mProducts__mBranches", branches);
    QuerySet<Supplier> suppliers = Supplier.objects(getContext()).filter(filter);
    assertEquals(1, suppliers.count());
    assertTrue(suppliers.contains(mS1));
    branches.remove(0);
    filter = new Filter();
    filter.in("mProducts__mBranches", branches);
    suppliers = Supplier.objects(getContext()).filter(filter);
    assertEquals(0, suppliers.count());
}
Also used : Filter(com.orm.androrm.Filter) Branch(com.orm.androrm.impl.Branch) ArrayList(java.util.ArrayList) Supplier(com.orm.androrm.impl.Supplier)

Example 8 with Supplier

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

the class FieldResulutionTest method testManyToManyFieldResolutionOnlyField.

public void testManyToManyFieldResolutionOnlyField() {
    List<Branch> branches = new ArrayList<Branch>();
    branches.add(mB1);
    branches.add(mB2);
    Filter filter = new Filter();
    filter.in("mBranches", branches);
    QuerySet<Supplier> suppliers = Supplier.objects(getContext()).filter(filter);
    assertEquals(1, suppliers.count());
    assertTrue(suppliers.contains(mS1));
    branches.remove(0);
    filter = new Filter();
    filter.in("mBranches", branches);
    suppliers = Supplier.objects(getContext()).filter(filter);
    assertEquals(0, suppliers.count());
}
Also used : Filter(com.orm.androrm.Filter) Branch(com.orm.androrm.impl.Branch) ArrayList(java.util.ArrayList) Supplier(com.orm.androrm.impl.Supplier)

Example 9 with Supplier

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

the class ForeignKeyFieldTest method testDoNotCascade.

public void testDoNotCascade() {
    Brand b = new Brand();
    b.setName("Copcal");
    b.save(getContext());
    Supplier s = new Supplier();
    s.setName("test_supplier");
    s.setBrand(b);
    s.save(getContext());
    b.delete(getContext());
    assertEquals(1, Supplier.objects(getContext()).count());
}
Also used : Brand(com.orm.androrm.impl.Brand) Supplier(com.orm.androrm.impl.Supplier)

Example 10 with Supplier

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

the class ManyToManyFieldTest method testAddAllAndGet.

public void testAddAllAndGet() {
    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());
    s = Supplier.objects(getContext()).get(s.getId());
    QuerySet<Product> products = s.getProducts(getContext());
    assertEquals(2, products.count());
    assertTrue(products.contains(p1));
    assertTrue(products.contains(p2));
}
Also used : Brand(com.orm.androrm.impl.Brand) Product(com.orm.androrm.impl.Product) Supplier(com.orm.androrm.impl.Supplier)

Aggregations

Supplier (com.orm.androrm.impl.Supplier)12 Filter (com.orm.androrm.Filter)6 Brand (com.orm.androrm.impl.Brand)6 Product (com.orm.androrm.impl.Product)6 ArrayList (java.util.ArrayList)4 Branch (com.orm.androrm.impl.Branch)3 DatabaseAdapter (com.orm.androrm.DatabaseAdapter)1 Model (com.orm.androrm.Model)1