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

Joining tables results in some null properties #67

Closed
tobrun opened this issue Feb 11, 2015 · 7 comments
Closed

Joining tables results in some null properties #67

tobrun opened this issue Feb 11, 2015 · 7 comments
Labels
Milestone

Comments

@tobrun
Copy link

tobrun commented Feb 11, 2015

Left join between 2 tables:

   final List<ProductRow> rows = new Select()
                .from(ProductRow.class)
                .join(PriceRecordRow.class, Join.JoinType.LEFT)
                .using(ProductRow$Table.ID)
                .queryList();

Returns a List of ProductRows, 2 fields of those items are not correctly initialised with values
(amount & unit fields not correctly initialised, tried both String as int representation).

Without a Join:

   final List<ProductRow> rows = new Select()
                .from(ProductRow.class)
                .queryList();

Returns a List of ProductRows, all fields are correctly initialised with values.

@agrosner
Copy link
Owner

Thanks for your issue report. I am working on getting a feature in that
will enable you to define @Join model classes that enable merging of
columns. Right now its fairly limited. Hopefully by the end of the week it
will be in.

On Wed, Feb 11, 2015 at 11:18 AM, Tobrun Van Nuland <
notifications@github.com> wrote:

Left join between 2 tables:

final List rows = new Select()
.from(ProductRow.class)
.join(PriceRecordRow.class, Join.JoinType.LEFT)
.using(ProductRow$Table.ID)
.queryList();

Returns a List of ProductRows, 2 fields of those items are not correctly
initialised with values
(amount & unit fields not correctly initialised, tried both String as int
representation).

Without a Join:

final List rows = new Select()
.from(ProductRow.class)
.queryList();

Returns a List of ProductRows, all fields are correctly initialised with
values.


Reply to this email directly or view it on GitHub
#67.

Andrew Grosner, Android Developer

Mobile Strategy, Design & Development

www.raizlabs.com | Check my calendar
https://www.google.com/calendar/embed?src=andrew.grosner@raizlabs.com&ctz=America/New_York&mode=WEEK
| @agrosner http://www.twitter.com/agrosner | 716-472-5075
[image: Raizlabs]

@tobrun
Copy link
Author

tobrun commented Feb 11, 2015

I'm not sure that this will resolve the problem, the referenced fields only occur in the ProductRow so I believe it is not linked too the joining mechanism itself (but is a small side effect). If I find some time, I will add sources and do some debugging.

Thanks for the quick reply,

@agrosner
Copy link
Owner

What is the SQL statement that is generated @tobrunvannuland ? thanks. It may be with how its generated or used. Thank you!

@agrosner agrosner added the bug label Feb 11, 2015
@agrosner agrosner added this to the 1.6.0 milestone Feb 11, 2015
@agrosner agrosner modified the milestones: 2.0.0, 1.6.0 Feb 24, 2015
@tobrun
Copy link
Author

tobrun commented Mar 5, 2015

After investigating the query and trying to do manipulations as a rawQuery. I can only conclude that this isn't a bug from dbflow.

Thanks again for this awesome fast library.

@tsuharesu
Copy link

I'm having quite the same problem. The query is this:

SELECT * FROM `Thing' AS T INNER JOIN `User` AS U ON `T`.`authorName`=U.name WHERE `U`.`id`=1 ORDER BY D.id 

It is returning the Things correctly, but all ids (I have a column named id) are 1.

EDIT: Now I see that the id column is 1 because my User id = 1. How can I return correctly?

@tsuharesu
Copy link

I tried doing Select("T.*") but it don't work too, DBFlow is putting backticks on *

@faifai21
Copy link

I think I just hit this bug but in an odd way. I was using an inner join, but the models I got back had the id's of the corresponding rows in the right (ApptPreview) table. This was my WhereClause:
new Select().from(Client.class).as("Client").join(ApptPreview.class, Join.JoinType.INNER) .on(Condition.column("Client." + Client$Table.ID).eq(ApptPreview$Table.CLIENTID)).where( Condition.column(ApptPreview$Table.BEGINAT).greaterThan(new Date())).groupBy( new QueryBuilder().appendQuoted("Client." + Client$Table.ID));

I think the bug had something to do with the fact that both tables had the same column for ID ("id"). The bug still surfaced when I used aliases. I managed to fix this bug by making the column names unique (I changed "id" on the Client table to "cltid". This isn't really the best course of action, but I guess it isn't too bad since we can just use migrations to update the table on existing databases.

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

No branches or pull requests

4 participants