Search code examples
activejdbc

How to return the first row using ActiveJDBC?


ActiveRecord has methods such as Entity.first, Entity.last, Entity.first.next etc (note there are no parameters passed).

Is there a similar construct in activejdbc?


Solution

  • There is "first": http://javalite.github.io/activejdbc/org/javalite/activejdbc/Model.html#first-java.lang.String-java.lang.Object...-

    , but not others.

    You can do this:

    User.findAll().orderBy("age").limit(1); //--> first
    User.findAll().orderBy("age desc").limit(1); //--> last
    

    this way you control exactly is returned.