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.

Duplicate array objects for cyclic many to many relations

See original GitHub issue

I have a many to many relations between two models. When I create 2 level cycle then duplicate objects are added to array. For example suppose I have two models User and Intersts and many to many relation between then like this:

User.schema = {
  name: 'User',
  primaryKey: 'id',
  properties: {
    id: { type: 'string', default: '' },
    name: { type: 'string', default: '' },
    interests: { type: 'list', objectType: 'Interest', default: [] },
  }
}

Interest.schema = {
  name: 'Interest',
  primaryKey: 'id',
  properties: {
    id: { type: 'string', default: '' },
    name: { type: 'string', default: '' },
    interestedUsers: { type: 'list', objectType: 'User', default: [] },
  }
}

When I try to insert following data with realm.create(<modelName>, <object>, true) it does that correctly: http://pastebin.com/pE1FFd5x

But on adding following data multiple entries for same interest is created for user: http://pastebin.com/FFLbR5CR

A demo project showing the issue is here: https://github.com/shahankit/realm-duplicate

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
alaziercommented, Sep 14, 2016

Will hopefully be able to start working on adding virtual properties/backlinks/#343 in the next two weeks.

2reactions
alaziercommented, Aug 15, 2016

We now have underlying core and object store support for computed properties and I hope this will make it into one of the next few releases, assuming we don’t run into technical issues in how we expose this functionality in the js layer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoid circular reference on many-to-many object relations
Now, circular references can be tricky to deal with if you need to ... You don't instantiate involved entities in the relation object....
Read more >
Circular dependency between 2 table with one to one and one ...
Cannot insert duplicate key row in object 'dbo.CompaniesUsers' with unique index 'IX_CompanyUsers'. The duplicate key value is (1, 1).
Read more >
Duplicate Any Object Around A Point (Circle) Using An Array ...
Hey guys, in today's tutorial I'm going to be showing you how to quickly and easily create a symmetrical object around a point/circle...
Read more >
Working with entity instances — Pony ORM documentation
The relationships between two objects are defined by two relationship attributes. If another side of the relationship is declared as a Set ,...
Read more >
Many-to-many relations - Prisma
Explicit many-to-many relations. In an explicit many-to-many relation, the relation table is represented as a model in the Prisma schema and can be...
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