Search in sources :

Example 6 with Branch

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

the class ManyToManyFieldTest method testSet.

public void testSet() {
    Product p = new Product();
    p.setName("test product");
    p.save(getContext());
    Brand b = new Brand();
    b.setName("Copcal");
    b.save(getContext());
    Branch b1 = new Branch();
    b1.setName("test branch");
    b1.setBrand(b);
    b1.addProduct(p);
    b1.addProduct(p);
    b1.save(getContext());
    Branch b2 = Model.objects(getContext(), Branch.class).get(b1.getId());
    assertEquals(1, b2.getProducts(getContext()).count());
    assertTrue(b2.getProducts(getContext()).contains(p));
}
Also used : Brand(com.orm.androrm.impl.Brand) Branch(com.orm.androrm.impl.Branch) Product(com.orm.androrm.impl.Product)

Example 7 with Branch

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

the class OneToManyFieldTest method testReset.

public void testReset() {
    Brand b = new Brand();
    b.setName("Copcal");
    b.save(getContext());
    Branch b1 = new Branch();
    b1.setName("test1");
    b1.setBrand(b);
    b1.save(getContext());
    Branch b2 = new Branch();
    b2.setName("test2");
    b2.setBrand(b);
    b2.save(getContext());
    Product p = new Product();
    p.addBranches(Arrays.asList(new Branch[] { b1, b2 }));
    p.save(getContext());
    assertEquals(2, p.getBranches(getContext()).count());
    p.delete(getContext());
    assertEquals(0, p.getBranches(getContext()).count());
}
Also used : Brand(com.orm.androrm.impl.Brand) Branch(com.orm.androrm.impl.Branch) Product(com.orm.androrm.impl.Product)

Example 8 with Branch

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

the class OneToManyFieldTest method testCount.

public void testCount() {
    Brand b = new Brand();
    b.setName("Copcal");
    b.save(getContext());
    Branch b1 = new Branch();
    b1.setName("test1");
    b1.setBrand(b);
    b1.save(getContext());
    Branch b2 = new Branch();
    b2.setName("test2");
    b2.setBrand(b);
    b2.save(getContext());
    b = Brand.objects(getContext()).get(b.getId());
    assertEquals(2, b.branchCount(getContext()));
}
Also used : Brand(com.orm.androrm.impl.Brand) Branch(com.orm.androrm.impl.Branch)

Example 9 with Branch

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

the class FieldResulutionTest method testOneToManyResolutionOnlyField.

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

Example 10 with Branch

use of com.orm.androrm.impl.Branch 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)

Aggregations

Branch (com.orm.androrm.impl.Branch)13 Brand (com.orm.androrm.impl.Brand)8 Filter (com.orm.androrm.Filter)5 ArrayList (java.util.ArrayList)5 Product (com.orm.androrm.impl.Product)4 Supplier (com.orm.androrm.impl.Supplier)3 DatabaseAdapter (com.orm.androrm.DatabaseAdapter)2 Model (com.orm.androrm.Model)2