-
Notifications
You must be signed in to change notification settings - Fork 306
Description
Hi,
I have the next structure:
@Entity
class CalEventEntity constructor(){
@Id(assignable = true)
var id: Long = 0
lateinit var recurrence: ToOne<CalEventRecurrenceEntity>
}
@Entity
data class CalEventRecurrenceEntity(@Id var id: Long=0,
var anchorUid: String?,
var originalStart: Long//,
/*var endsAt : Long*/)
{
@Backlink
lateinit var rules: ToMany<RecurrenceRuleEntity>
}
@Entity
data class RecurrenceRuleEntity(@Id var id: Long=0,
var rule : String) {
lateinit var eventRecurrence: ToOne<CalEventRecurrenceEntity>
}
Full logic Description:
-
I am getting from server the CalEventEntity with predefined id and then i am attaching it to the box: DBManager.eventDAO.box().attach(eventEntity)
-
I am creating a new instance :
val calEventRecurrenceEntity = CalEventRecurrenceEntity(0,null,0) //notice the id is 0 as required -
Then i am creating a new instance:
val ruleEntity = RecurrenceRuleEntity(0, rule) -
adding the rule: calEventRecurrenceEntity.rules.add(ruleEntity)
-
Adding the recurrence object to the calEvent:
eventEntity.recurrence.target = calEventRecurrenceEntity
The problem is that the rules are not saved in the DB, i think that the problem is the the CalEventEntity has already ID.
Anyway, i expect the code to update the calEventEntity and insert the CalEventRecurrenceEntity with it's relations to the DB.
full code
val eventEntity = CalEventEntity(calEvent.id)
DBManager.eventDAO.box().attach(eventEntity)
val calEventRecurrenceEntity = CalEventRecurrenceEntity(0,calEvent.recurrence.anchorRefId, calEvent.recurrence.originalStart)
if (calEvent.recurrence.rules != null) {
for (rule in calEvent.recurrence.rules) {
val ruleEntity = RecurrenceRuleEntity(0, rule)
calEventRecurrenceEntity.rules.add(ruleEntity)
}
}
eventEntity.recurrence.target = calEventRecurrenceEntity
Please help.