-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Another Primary Key issue #7
Comments
Thanks for providing that code, I'll try running that in a test myself and figure out what's going on. With your second question, are you stating that you:
I'm not sure what the issue is here exactly, but I will mention that since you cannot update a However, if you set An additional thought, instead of creating an object on the client and getting the primary key from the server, have you thought of generating a UUID on the client for that object and then sending that UUID to the server? UUID's were made to avoid collisions in cases like this. You could use |
That's exactly I ment. I got what you explained in mind but the tests didn't pass I couldn't get it to work any further, erasing the Tomorrow I'll bring you more news on this!! |
Awesome! Looking forward to hearing more info! |
Update: User_spec__Should_decode_JSON_User_objects
/Users/buddybuild/workspace/EbikemotionTests/UserSpec.swift:38
failed: caught "Invalid value", "Expected object of type string for property 'identifier' on object of type 'User', but received: 170" When running tests without the Realm |
Thanks for the info, looking into that now. Btw, in the case with a In the meantime, I'll try to figure out why this still throws an exception when not even using a |
Oh this is why
Changing
|
But... I'm using a custom transform to cast the Integer returned from the JSON to the String of the Model, Am I wrong? public class PrimaryKeyMapping: Transform {
public typealias MappedObject = String
public func fromJSON(json: JSONValue) throws -> MappedObject {
switch json{
case .JSONNumber(let number):
return "\(NSNumber(double: number).integerValue)"
default:
throw NSError(domain: "", code: -1, userInfo: nil)
}
}
public func toJSON(obj: MappedObject) -> JSONValue {
return JSONValue.JSONNumber(Double(obj)!)
}
} |
Huh, you bring up a good point. I hadn't written the Transform to map the data before a search query. Sounds reasonable though and a feature we should add. I'll see what kind of solution I can come up with. |
Ooooooh is that why! I didn't even realized It was a conflict with the way the data checked the existance of an object! You might think of me as a nighmare from now on... 😵 |
Lol! No, it's totally a good thing you're bringing up points like this I hadn't considered. Just makes the library more robust. We could probably add a transform to the
We may even want to enhance
It's a little complex, but should cover every edge case. This work for you? |
It seems fine to me, I actually like closures... haha. I think that with this we solve the issue where the |
Hello!
I'm working with latest version of both Realm, RealmCrust and Crust libraries. I'm getting new issues. In the following model with custom transformations:
I apply the following tests:
The second one crashes with
Primary key cannot be modified after object is inserted
, but I'm not modifying anything from that object, just encoding it to JSON... Just for let you know it.Also, is there any way to use the side of Crust of
PrimaryKeys
without using the Realm side? An example: I generate a model that has not primary key until it's synchronized with a server which returns me the primary key for that object, but that synchronization could happen when the model is already saved on theRealm
soprimaryKey()
isn't what I'm looking for. But using CrustprimaryKeys
should fit using that supposed primary key to update an already saved Model or even update it with information taking in mind that although the model has no primary key itself from Realm, Crust is trying to find the object in the database before creating a new one. I don't know if I'm explaining well.The text was updated successfully, but these errors were encountered: