Search in sources :

Example 6 with Filter

use of com.orm.androrm.Filter in project androrm by androrm.

the class FilterTest method testInFilterModel.

public void testInFilterModel() {
    Person p = new Person();
    p.setName("tom");
    p.save(getContext());
    Car c = new Car();
    c.addDriver(p);
    c.setName("Toyota");
    c.save(getContext());
    List<Person> drivers = new ArrayList<Person>();
    drivers.add(p);
    Filter filter = new Filter();
    filter.in("mDrivers", drivers);
    QuerySet<Car> cars = Car.objects(getContext()).filter(filter);
    assertEquals(1, cars.count());
}
Also used : Car(com.orm.androrm.impl.Car) Filter(com.orm.androrm.Filter) ArrayList(java.util.ArrayList) Person(com.orm.androrm.impl.Person)

Example 7 with Filter

use of com.orm.androrm.Filter in project androrm by androrm.

the class FilterTest method testNoSuchFieldException.

public void testNoSuchFieldException() {
    Filter filter = new Filter();
    filter.is("no_such_field", "value");
    try {
        Brand.objects(getContext()).filter(filter);
        fail();
    } catch (NoSuchFieldException e) {
    }
}
Also used : Filter(com.orm.androrm.Filter) NoSuchFieldException(com.orm.androrm.field.NoSuchFieldException)

Example 8 with Filter

use of com.orm.androrm.Filter in project androrm by androrm.

the class QuerySetTest method testContains.

public void testContains() {
    Filter filter = new Filter();
    filter.contains("mName", "Pretoria");
    Branch contained = Branch.objects(getContext()).get(1);
    Branch notContained = Branch.objects(getContext()).get(3);
    QuerySet<Branch> result = Branch.objects(getContext()).filter(filter);
    assertTrue(result.contains(contained));
    assertFalse(result.contains(notContained));
}
Also used : Filter(com.orm.androrm.Filter) Branch(com.orm.androrm.impl.Branch)

Example 9 with Filter

use of com.orm.androrm.Filter in project androrm by androrm.

the class QuerySetTest method testFilter.

public void testFilter() {
    Filter filter = new Filter();
    filter.contains("mName", "Pretoria");
    assertEquals(2, Branch.objects(getContext()).filter(filter).count());
}
Also used : Filter(com.orm.androrm.Filter)

Example 10 with Filter

use of com.orm.androrm.Filter in project androrm by androrm.

the class FieldResulutionTest method testOneToManyResolutionInBetween.

public void testOneToManyResolutionInBetween() {
    Filter filter = new Filter();
    filter.contains("mProducts__mBranches__mName", "cash");
    QuerySet<Supplier> suppliers = Supplier.objects(getContext()).filter(filter);
    assertEquals(1, suppliers.count());
    assertTrue(suppliers.contains(mS1));
    filter = new Filter();
    filter.contains("mProducts__mBranches__mName", "plumb");
    suppliers = Supplier.objects(getContext()).filter(filter);
    assertEquals(0, suppliers.count());
}
Also used : Filter(com.orm.androrm.Filter) Supplier(com.orm.androrm.impl.Supplier)

Aggregations

Filter (com.orm.androrm.Filter)21 ArrayList (java.util.ArrayList)7 Supplier (com.orm.androrm.impl.Supplier)6 Branch (com.orm.androrm.impl.Branch)5 Product (com.orm.androrm.impl.Product)5 Rule (com.orm.androrm.Rule)3 InStatement (com.orm.androrm.statement.InStatement)3 LikeStatement (com.orm.androrm.statement.LikeStatement)3 Statement (com.orm.androrm.statement.Statement)3 Person (com.orm.androrm.impl.Person)2 EmptyModel (com.orm.androrm.impl.migration.EmptyModel)2 NewEmptyModel (com.orm.androrm.impl.migration.NewEmptyModel)2 Migrator (com.orm.androrm.migration.Migrator)2 QuerySet (com.orm.androrm.QuerySet)1 NoSuchFieldException (com.orm.androrm.field.NoSuchFieldException)1 Car (com.orm.androrm.impl.Car)1 ModelWithRelation (com.orm.androrm.impl.migration.ModelWithRelation)1 NewModelWithRelation (com.orm.androrm.impl.migration.NewModelWithRelation)1