Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model is filled with wrong columns when using joins #106

Open
frigus02 opened this issue Aug 22, 2013 · 3 comments
Open

Model is filled with wrong columns when using joins #106

frigus02 opened this issue Aug 22, 2013 · 3 comments

Comments

@frigus02
Copy link

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

@tristanoneil
Copy link

👍 Had this same exact issue.

@Knickedi
Copy link

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!

@sabadow
Copy link

sabadow commented May 28, 2014

I create a pull request to fix this issue :-)
#230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants