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

New property does not have Kotlin default value when getting existing entity #664

Closed
jrcacd opened this issue Feb 20, 2019 · 2 comments
Closed

Comments

@jrcacd
Copy link

jrcacd commented Feb 20, 2019

ObjectBox 2.3.3

In Kotin, when we create a field on an existing entity, the field on the existing records is not pupulated with the default value.

Example:

Before
Entity

data class Record(
        @Id var id: Long= 0,
        var uuid: String = "")

After

data class Record(
        @Id var id: Long= 0,
        var uuid: String = "",
        var date: Long = Date.now().toMillis()) //New one

Result:
Field date content: 0

shouldn't have the Date.now().toMillis() value?

@greenrobot-team
Copy link
Member

greenrobot-team commented Feb 26, 2019

Can you try making your new property nullable, like var date: Long?.

The issue is that ObjectBox will map a null database entry to your non-nullable type, which for Long is 0. If you make the property nullable ObjectBox should set it to null instead.

This is related to #157 and #589.

@greenrobot-team greenrobot-team changed the title When creating a new entity field, the existing records are not pupulated with the default value on that field New property does not have Kotlin default value when getting existing entity Feb 26, 2019
@greenrobot-team
Copy link
Member

greenrobot-team commented Feb 26, 2019

Closing as duplicate of #157. -ut

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

2 participants