Search in sources :

Example 11 with Product

use of com.orm.androrm.impl.Product 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 12 with Product

use of com.orm.androrm.impl.Product 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 13 with Product

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

the class TableDefinitionTest method testForeignKeyField.

public void testForeignKeyField() {
    TableDefinition def = new TableDefinition("foo");
    ForeignKeyField<Product> fk = new ForeignKeyField<Product>(Product.class);
    def.addField("product", fk);
    assertEquals("CREATE TABLE IF NOT EXISTS `foo` (" + "`product` integer," + "FOREIGN KEY (`product`) " + "REFERENCES `product` (`mId`) " + "ON DELETE CASCADE);", def.toString());
}
Also used : ForeignKeyField(com.orm.androrm.field.ForeignKeyField) TableDefinition(com.orm.androrm.TableDefinition) Product(com.orm.androrm.impl.Product)

Example 14 with Product

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

the class ForeignKeyFieldTest method testSetAndGet.

public void testSetAndGet() {
    Product p = new Product();
    p.setName("test product");
    ForeignKeyField<Product> fk = new ForeignKeyField<Product>(Product.class);
    fk.set(p);
    assertEquals(p.getName(), fk.get(getContext()).getName());
    p.save(getContext());
    fk = new ForeignKeyField<Product>(Product.class);
    fk.set(p.getId());
    assertEquals(p.getName(), fk.get(getContext()).getName());
}
Also used : ForeignKeyField(com.orm.androrm.field.ForeignKeyField) Product(com.orm.androrm.impl.Product)

Example 15 with Product

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

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