DBFlow icon indicating copy to clipboard operation
DBFlow copied to clipboard

on save() foreign key can't be null

Open OptimistNot opened this issue 11 years ago • 13 comments

Hi! Im trying to save jsonmodel and passing some foreign keys that has null values as a relation is not defined yet. I got NullPointerException in bindToStatement in $Container. How do i allow it to save null values in foreign keys? (i tried these: notNull = false, saveForeignKeyModel = false, still no results)

Thanks

OptimistNot avatar Apr 27 '15 11:04 OptimistNot

Hey can you send me what your model looks like? thank you.

agrosner avatar Apr 27 '15 14:04 agrosner

http://pastebin.com/KZ6rbw8A where AQL and Supplier foreign keys can have null values

OptimistNot avatar Apr 27 '15 14:04 OptimistNot

It's a bug. I will add a check to ensure that the getValue is not null for the ModelContainer as foreign key. Also adding unit test here.

agrosner avatar Apr 27 '15 18:04 agrosner

Nice find!

agrosner avatar Apr 27 '15 18:04 agrosner

Meanwhile is there any quick fix? Thanks in advance.

OptimistNot avatar Apr 27 '15 18:04 OptimistNot

@OptimistNot not for such an error. Can you send me the $Container generated class as well and line number its failing on? thanks

agrosner avatar Apr 27 '15 18:04 agrosner

http://pastebin.com/sLV4UxLw on lines 145-148

OptimistNot avatar Apr 27 '15 18:04 OptimistNot

Also can you ensure all inner classes have @ContainerAdapter annotatons?

agrosner avatar Apr 27 '15 19:04 agrosner

NVM. It may be a conversion from a null Long to a long

agrosner avatar Apr 27 '15 19:04 agrosner

Maybe, but there is nothing i can do about it. If i have null value there is no long foreign key to look for. I tried today to fork dbflow and include in my project to change columndefinition class to add if null condition for container but i really stuck with it... I cant get Android studio to include the module, and i need a fast solution.

OptimistNot avatar Apr 27 '15 19:04 OptimistNot

@OptimistNot its going to be fully fixed in 2.0.0 now. I had to rewrite the underlying code generator and consequently does some breaking changes (but for consitency and the better) so 2.0.0 should be released soon instead of 1.9.0

agrosner avatar Apr 30 '15 20:04 agrosner

hopefully EOD tomorrow or Monday

agrosner avatar Apr 30 '15 20:04 agrosner

Thank you for your quick response! Sorry hurry u up... Waiting for 2.0.0 to be released as soon as possible :) Thanks!

OptimistNot avatar May 04 '15 09:05 OptimistNot