memtrip / SQLKing

SQLKing is an Android SQLite ORM powered by an annotation preprocessor, tables are defined by Table annotations and CRUD classes expose an expressive api for executing SQLite queries. @memtrip
Other
21 stars 9 forks source link

Retrieving columns from related tables with Joins #10

Closed Trellian closed 8 years ago

Trellian commented 8 years ago

Hi Sam,

Is it possible to retrieve columns from tables that have been joined? Looking at the examples in the tests, it seems that only the root table columnset is returned.

eg. below, the return is of Class User, I can't see how to retrieve the Log columns.

        User[] users = Select .getBuilder()
                .join(innerJoin(Log.class, on("User.logId", "Log.id")))
                .execute(User.class, getSQLProvider());

Thanks, Adrian

samkirton commented 8 years ago

Hi Adrian,

If you see inside User there is an @Column of Log, for each user that matches the join condition, the nested Log object will be populated. So in this example the users[0].getLog(); will return the log associated with the user.

Cheers, Sam

samkirton commented 8 years ago

Debugging the sample and seeing the output from the inner join might make things clearer: https://github.com/memtrip/SQLKing/blob/master/sample/app/src/main/java/com/memtrip/sqlking/sample/comment/CommentActivity.java#L144

Cheers, Sam