Search code examples
activejdbc

activejdbc include parent recursively


I'm work with activejdbc and:

I have 3 Models: City belongs to State belongs to Country, ok? I do this:

Paginator p = new Paginator(City.class, count, filters).orderBy(orderParams); LazyList page = p.getPage(pag).include(State.class);

This, loads cities with their states (i do page.toMaps()),

Now I want to load the country also

It's possible?


Solution

  • The include() method goes on dependencies only one level up or down. This means that if you are starting at the level of CIty, you can only get a state. If you want to get both, you can start at the level of State like this:

    Paginator p = new Paginator(State.class, count, filters) 
                                           .orderBy(orderParams); 
    LazyList page = p.getPage(pag).include(City.class, Country.class);
    

    Not sure of this will work for you though. Here is an example without the Paginator: http://javalite.io/lazy_and_eager#eager-simultaneous-loading-of-parents-and-children