question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expected behavior for relations when putting entity

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
vadimh77commented, Feb 6, 2018

Tnx for your help, it seems that the problem solved.

0reactions
greenrobotcommented, Feb 6, 2018

@vadimh77 please let us know if you see how this could be improved/simplified.

Read more comments on GitHub >

github_iconTop Results From Across the Web

About table relationships for Microsoft Dataverse - Power Apps
Behaviors for related tables is important because it helps ensure data integrity and can automate business processes for your company. Preserve ...
Read more >
Entities in Backlink ToMany reappearing after removing #1065
Put the parent ( one ) in the box again (overriding it). Expected behavior. No matter the order, if an entity gets deleted...
Read more >
5. Relationships : ArchiMate® 3.1 Specification
Aggregation, composition, and specialization relationships are always permitted between two elements of the same type, and association is always allowed between ...
Read more >
Multiple Relationships to same Related entity - Dynamics 365 ...
I understand that the Relation Type of Behavior is determining how entities relate to each other and that you can setup what to...
Read more >
The Healthy Relationship Boundary You Might Be Missing
All healthy relationships have boundaries. “When it comes to your life as a couple, consider that there are actually three entities involved: yourself,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found