Comments (14)
Yep, both worked fine with v11, will try and reproduce with a test when I have a moment and get back to you
from realm-js.
➤ PM Bot commented:
Jira ticket: RJS-2744
from realm-js.
@mattlewer Thank you for reporting. Is it possible for you to share the schema?
from realm-js.
@mattlewer Thank you for reporting. Is it possible for you to share the schema?
Hopefully this helps
Config
export const config: Realm.Configuration = {
schema: [
OrganisationRealm,
Session,
User,
],
schemaVersion: 4,
};
export default createRealmContext(config);
Session
import {Realm} from '@realm/react';
import User from './User';
import idGenerator from '../../services/idGenerator';
export default class Session extends Realm.Object {
client_id!: string;
user!: User;
static create(user: User): Object {
return {
user: user,
};
}
static schema = {
name: 'Session',
primaryKey: 'client_id',
properties: {
client_id: {type: 'string', default: () => idGenerator.generate()},
user: 'User',
},
};
}
User
import 'react-native-get-random-values';
import {Realm} from '@realm/react';
import idGenerator from '../../services/idGenerator';
import {Organisation} from './Organisation';
export default class User extends Realm.Object {
client_id!: string;
id!: number;
inviting_organisations?: Organisation[];
static schema = {
name: 'User',
primaryKey: 'id',
properties: {
client_id: {type: 'string', default: () => idGenerator.generate()},
id: 'int',
inviting_organisations: 'Organisation[]',
},
};
}
Organisation
import 'react-native-get-random-values';
import {Realm} from '@realm/react';
import idGenerator from '../../services/idGenerator';
export interface Organisation extends Syncable {
client_id: string;
id: number;
name: string;
created_at: Date;
updated_at: Date;
}
export class OrganisationRealm extends Realm.Object implements Organisation {
client_id!: string;
id!: number;
name!: string;
created_at!: Date;
updated_at!: Date;
resource!: string;
static schema = {
name: 'Organisation',
primaryKey: 'id',
properties: {
client_id: {type: 'string', default: () => idGenerator.generate()},
id: 'int',
name: 'string',
created_at: {type: 'date', default: () => new Date()},
updated_at: {type: 'date', default: () => new Date()},
resource: {type: 'string', default: SyncResource.Organisations},
},
};
}
Syncable
export interface Syncable {
id?: number;
client_id?: string;
created_at: Date;
updated_at: Date;
is_synced?: boolean;
resource?: string;
}
SyncResource
export enum SyncResource { Organisations = 'organisations', }
idGenerator
const idGenerator = () => {
const generate = (): string => {
return new Realm.Types.UUID().toHexString(true);
};
return {
generate,
};
};
export default idGenerator();
from realm-js.
It sounds like the same as #6129 and we released a fix for it in v12.2.0.
from realm-js.
Has this potentially regressed since as I'm using v12.6.0? Will downgrade to v12.2.0 to see if it makes a difference and get back to you
from realm-js.
downgrade to v12.2.0 to see if it makes a difference
Thanks!
from realm-js.
Same error:
Original update function:
Error: Attempting to create an object of type 'User' with an existing primary key value '341'
Adapted update function:
Error: Attempting to create an object of type 'Organisation' with an existing primary key value '454'.
from realm-js.
So the first error is expected:
realm.write(() => {
session.user = updatedUser;
});
where updatedUser
is an unmanaged object will attempt to first add it to realm and then set session.user
to it. In the case where the user already exists, you're supposed to get an error.
The second code snippet points to a legitimate bug though, however I've been unable to reproduce it. I've attached my attempt to repro this - if you can modify it in a way that triggers the duplicate PK error, let us know and we'll continue investigating.
from realm-js.
Thank you for getting back to me, I will have a look ASAP.
Given the above situation, what would be the correct way to update this nested object? I would assume that because it comes down with the same primary key as the object currently stored in the DB, it would successfully match these up and update it, I don't quite understand why it would cause an error?
Also as this worked fine in v11, is there something specific that has caused this breaking change? If I downgrade again, everything works as intended.
from realm-js.
Did
update(() => {
session.user = updatedUser;
});
work with v11? If it did, it's definitely unintended and likely a bug with v11. The other code snippet - i.e.:
realm.write(() => {
realm.create(
'session',
merge({}, original, changes),
Realm.UpdateMode.Modified,
);
});
Should work in both v11 and v12 and is the right way to do it. If it doesn't work with v12, then we should definitely fix it, but I can't repro it so far.
from realm-js.
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.
from realm-js.
will try and reproduce with a test when I have a moment and get back to you
Any chance you have a moment to create a reproduction case for us?
from realm-js.
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.
from realm-js.
Related Issues (20)
- UserProvider doesn't unmount Login-Component HOT 7
- SDKs should not consume stitch_ prefixed fields HOT 1
- Unable to resolve module node:os HOT 5
- Unable to load an existing partition based local database (back of synced realm) to new flexible sync realm HOT 2
- relationships create whole object in realm list instead having reference HOT 1
- Realm app fails to authenticate users when running on Android emulator HOT 1
- Error when building the Android binding with an unexpected NDK HOT 1
- Refactor `ProgressRealmPromise` to register progress notifier only if needed HOT 1
- useObject and reinsertion item HOT 2
- Initializing a named sync Subscription leads to "undefined" HOT 6
- Major Bug: Documents and what library having is different with Listeners HOT 7
- SigSev Android 14 React Native 0.74.1 HOT 3
- Remove `use_frameworks` hack from Podspec HOT 1
- Upgrade to Realm Core v14.9.0 HOT 1
- NPM Always ask to install [email protected] instead of [email protected] ( in package.json ) HOT 2
- Unable to handle a manual client reset due to a missing function HOT 1
- logInWithFacebook is not working with iOS Limited Login HOT 1
- Run bindgen with symbols missing from opt-in list removed HOT 2
- Issue building for ARM/Linux HOT 4
- Inaccurate Return Type for `toJSON` Method in `RealmObject` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from realm-js.