Giter Site home page Giter Site logo

Comments (11)

martijnwalraven avatar martijnwalraven commented on June 16, 2024

Good to hear you're finding it useful, even without decent documentation! Are you using it from Swift or Objective-C?

The _id- field is actually used to construct the Core Data objectID. METCoreDataDDPClient exposes objectIDForDocumentKey: that you can use to get from a key (a combination of collection name and documentID) to an NSManagedObjectID:

NSManagedObjectID *objectID = [client objectIDForDocumentKey:[METDocumentKey keyWithCollectionName:@"todos" documentID:@"bla"]];
NSManagedObject *object = [managedObjectContext objectWithID:objectID];

I'm still working out the API, so consider this a temporary solution. What is your intended usage pattern here? Where does the _id value come from?

from meteor-ios.

trevorbroad avatar trevorbroad commented on June 16, 2024

It is pretty difficult without docs, I'm also new to iOS development so the difficulty is compounded, I'm basically muddling through. Do you have a swift example? I'm just trying to lookup an existing object and update some values.

from meteor-ios.

martijnwalraven avatar martijnwalraven commented on June 16, 2024

I can imagine the difficulty! Hopefully I'll find some time over the next few weeks to work on the documentation and maybe even write a tutorial. I'm in the middle of a deadline for a project and the API is still in a bit of a flux, so it'll be a while before things get stable. Core Data in itself isn't very user friendly, so I'm also working on some helper classes and extensions in Swift to make things easier.

This should work for now:

let objectID = Meteor.objectIDForDocumentKey(METDocumentKey(collectionName: "todos", documentID: "bla"))
let object = managedObjectContext.objectWithID(objectID)

from meteor-ios.

trevorbroad avatar trevorbroad commented on June 16, 2024

That's great, worked for me, thanks!

from meteor-ios.

trevorbroad avatar trevorbroad commented on June 16, 2024

Hey again, I'm now looking for a way to get the meteor ID of an object I've created. Essentially, I'm creating an object, then creating related objects and need to add the ID of the original object to the related ones. How can I get the ID of an object I already have in the managed object?

from meteor-ios.

martijnwalraven avatar martijnwalraven commented on June 16, 2024

I'm planning on simplifying this, but right now you can get the document ID of an object by using:

let object: NSManagedObject = ...
let documentID = Meteor.documentKeyForObjectID(object.objectID).documentID

I'm not sure how you're setting up relationships, but in most cases it shouldn't be necessary to connect objects manually by ID. If you define a relationship in your Core Data model and set its value, a field with the related document ID (or array of document IDs) will be managed for you.

from meteor-ios.

trevorbroad avatar trevorbroad commented on June 16, 2024

That would be better, can you point me to the place in your Todos example where I can get a sense of how to make that connection? (I'm using the swift version) I did some setup to relationships in the Core Data model, but I must be missing something because its not adding the IDs for me

from meteor-ios.

martijnwalraven avatar martijnwalraven commented on June 16, 2024

It should work with any properly set up Core Data relationship. There is no additional code required, you simply define the relationship in the managed object model. The only issue to keep in mind is that by default it will add IDs on both sides of the relationship. You'll have to specify 'storage = false' as user info on one of the relationship sides to suppress this (for many-to-many you need both sides).

Here are two screenshots from the Todos example:

screen shot 2015-02-17 at 07 34 04

screen shot 2015-02-17 at 07 34 24

from meteor-ios.

trevorbroad avatar trevorbroad commented on June 16, 2024

I have it setup essentially the same as in the screens, but it doesn't seem to be adding the values automatically. To be clear, I'm looking to have the MongoDB '_id' field for the List object inserted into the todo object as a new field on creation. Is that what should be happening?

from meteor-ios.

martijnwalraven avatar martijnwalraven commented on June 16, 2024

Yes, if you set todo.list to a List object, a listId field with the list _id value should be inserted automatically into the todo document. Are you sure you're setting the list property? And have you defined it as a managed property in the Todo class?

@NSManaged var list: List!

from meteor-ios.

trevorbroad avatar trevorbroad commented on June 16, 2024

ah yes! I was trying to add it manually as a new field, but this is much better. Thanks!

from meteor-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.