Skip to content

Expected behavior for relations when putting entity #353

@vadimh77

Description

@vadimh77

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:

  1. I am getting from server the CalEventEntity with predefined id and then i am attaching it to the box: DBManager.eventDAO.box().attach(eventEntity)

  2. I am creating a new instance :
    val calEventRecurrenceEntity = CalEventRecurrenceEntity(0,null,0) //notice the id is 0 as required

  3. Then i am creating a new instance:
    val ruleEntity = RecurrenceRuleEntity(0, rule)

  4. adding the rule: calEventRecurrenceEntity.rules.add(ruleEntity)

  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions