ActiveAndroid icon indicating copy to clipboard operation
ActiveAndroid copied to clipboard

Model is filled with wrong columns when using joins

Open frigus02 opened this issue 13 years ago • 3 comments

I have these tables:

A           B          C
---------   --------   ------
Id Name     Id Desc    Id A B
1  Apple    3  round   5  1 3
2  Banana   4  long    6  2 4

When I make this Query:

new Select().from(A.class)
    .join(C.class).on("C.A = A.Id")
    .where("C.B = 3")
    .execute();

The Id in the resulting A-Model is 5, which is the Id from the C-Model. I guess it's because in the Model.loadFromCursor method the resulting columns are identified by name. However, the name "Id" exists 2 times and it seems to pick the wrong column.

I solved it by making a projection on the columns of the A-Model only in the Select constructor. But it would be nice, if this could be automatically solved.

But nevertheless great library. Greetings, Jan

frigus02 avatar Aug 22 '13 22:08 frigus02

:+1: Had this same exact issue.

tristanoneil avatar Nov 04 '13 20:11 tristanoneil

Still confirmed :-(

Makes the join query unusable if columns have same names because the cursor is picking the wrong column index for the result. Seems to pick the last column in my case. But I can't think of an elegant solution for this myself :-D

Had to work around with a subquery instead: new Select().from(Project.class).where("Id in (select ProjectId from ProjectToUser)").execute()

Still, ActiveAndroid is awesome!

Knickedi avatar May 27 '14 21:05 Knickedi

I create a pull request to fix this issue :-) https://github.com/pardom/ActiveAndroid/pull/230

sabadow avatar May 28 '14 18:05 sabadow