Code Monkey home page Code Monkey logo

Comments (10)

martijnwalraven avatar martijnwalraven commented on June 2, 2024

No, you don't need to use a special package. But you will have to make sure to either use reference fields with conventional names or customize the mapping.

from meteor-ios.

callmeahab avatar callmeahab commented on June 2, 2024

You could send related objects from the server with https://github.com/englue/meteor-publish-composite

from meteor-ios.

philipheinser avatar philipheinser commented on June 2, 2024

I have an optional field createdBy in my application. When I define this das an string in my model and in the datamodel i get as value the id of of the user created this object.

 @NSManaged var createdBy: String?

 @NSManaged var createdBy: User?

If I switch it two be an User in my model and create a relationship in the datamodel i always get nil for this field.

I also have trouble just declare it as a string because i don't know how to fetch and object by the meteor _id with this framework.

@callmeahab we use this package on the server and in the web this works fine.

from meteor-ios.

callmeahab avatar callmeahab commented on June 2, 2024

You can send the user object from the server using publishComposite.
Or you can declare a separate field on the object that has createdBy, then fetch the user from the server. To do this you need to subscribe to users collection, then apply a fetch predicate to a fetch request. To get the mongo id of the object you can do let userId = Meteor.documentKeyForObjectID(user.objectID).documentID as! String.

from meteor-ios.

philipheinser avatar philipheinser commented on June 2, 2024

I use publishComposite but it does not work for me with in the iOS app.

from meteor-ios.

philipheinser avatar philipheinser commented on June 2, 2024

I still try to get the user that belongs to the event. This code crashes when i print the username.

if let userKey = event.createdBy {

                    let id = Meteor.objectIDForDocumentKey(METDocumentKey(collectionName: "user", documentID: userKey))
                    let user = Meteor.mainQueueManagedObjectContext.objectWithID(id) as! User
                    print(user.username)
                }

from meteor-ios.

martijnwalraven avatar martijnwalraven commented on June 2, 2024

Are you sure you're publishing the user? Can you check to see if user is nil?

Also, you shouldn't need to manually look up a relationship value. You should be able to just define a createdBy relationship in the managed object model and use:

@NSManaged var createdBy: User?

By default, this will look for a field named createdById, but you can customize the mapping.

from meteor-ios.

philipheinser avatar philipheinser commented on June 2, 2024

How would I customize the mapping?

Am 01.08.2015 um 03:29 schrieb Martijn Walraven [email protected]:

Are you sure you're publishing the user? Can you check to see if user is nil?

Also, you shouldn't need to manually look up a relationship value. You should be able to just define a createdBy relationship in the managed object model and use:

@NSManaged var createdBy: User?
By default, this will look for a field named createdById, but you can customize the mapping.


Reply to this email directly or view it on GitHub #48 (comment).

from meteor-ios.

martijnwalraven avatar martijnwalraven commented on June 2, 2024

You can specify a fieldName as userInfo in the model editor (see Todos example).

from meteor-ios.

philipheinser avatar philipheinser commented on June 2, 2024

@martijnwalraven Thanks the problem was the default mapping does not apply to our server.

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.