objectbox / objectbox/objectbox-java
Default values for new properties
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 4.6k
- Fork
- 311
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Im using ObjectBox in a pet android project written in Kotlin.. I have a data class encoded as such (example):
@Entity data class Foo(var name:String, var description: String) {
constructor() : this("", "") // parameter-less constructor
@Id var id: Long = 0L
// other stuff
}
Database already existed on the device.. I added an additional property to the Foo class (not in the data constructor):
@Entity data class Foo(var name:String, var description: String) {
constructor() : this("", "") // parameter-less constructor
@Id var id: Long = 0L
var bar: String = ""
// other stuff
}
defaulted, non-null object bar.. however when pulling existing records from the stored box, that value bar appears to be null.. I would expect it to be a blank string (default for the parameter); is the violation of not-null guarantee coming from the Java interop?
I fixed the issue by nuking the database; afterwords the entity created and stored is not-null.. But this brings up any possible future updates that may violate this.
Is there a "database upgrade" method for updating already stored objects between versions, adding default values to new properties, or am I resigned to make anything added to an existing model be nullable (and handle it as such)?
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
La issue fornisce un’entità Foo in Kotlin e descrive record esistenti in un database ObjectBox, ma non indica file del repository né test. Inizia riproducendo il comportamento dopo aver aggiunto bar a Foo, quindi esamina la migrazione dell’entità e i percorsi di caricamento dei record esistenti. Il lavoro è completato quando è stato stabilito come le nuove proprietà non nullable ricevono valori predefiniti per i record memorizzati, con copertura dei test o documentazione per gli aggiornamenti futuri.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- android, java, kotlin
- Ambito
- databases, mobile-dev
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100