maskarade/Android-Orma

Rails' ActiveRecord-like scopes

Opened this issue · 0 comments

gfx commented

http://guides.rubyonrails.org/active_record_querying.html#scopes

Scoping allows you to specify commonly-used queries which can be referenced as method calls on the association objects or models. With these scopes, you can use every method previously covered such as where, joins and includes. All scope methods will return an

I'm planning something like this:

@Table
public class Todo {
  // ...

  @Column(indexed = true)
  public Date createdAt;

  @RelationMixin
  public static Todo_Relation today(Todo_Relation relation) {
    return relation.createdAtGe(calculateTodayStartedDate());
  }
}

The @RelationMixin injects methods to Todo_Relation:

// generated code!

public class Todo_Relation {

  public Todo_Relation today() {
    return Todo.today(this);
  }

}