I have two tables each with one record(for testing and question purposes). These tables are Post and Comment. Post has a PFRelation called myComment (I know only one comment - lets call it a feature for now). If I query Post, how do I get the Post and Comment data back?
Can't find this anywhere using web search engines or Parse docs (not a complete answer at least).
Because Relation in Parse is just like its literal meaning, it does not contain any data. If you want to get the data back, you need to get that instance of Relation first. Then call query from that instance. After that, you just perform that query if you want to get all objects from this Relation. You can also add some constraints after getting the query from Relation.
If you use Pointer type, you can just get back the data by using includeKey:.
Related
I'm using Entity Framework 6 and OData. I have a model A with several nav properties to other models, for example, model B. For a Get, I want to be able to call A, and Expand to B (I can do this successfully). The tricky bit is that now I want to be able to call Patch, and inside the body, include all the data for A as well as the nested data for B.
I know that EF does not accept data in virtuals, so I figured I could pull that data our in my application and null out those fields manually before saving with EF. That would be great.
However, the only way I can get OData to accept my subobject is by specifying that the type of the property B is a complex object, by adding this line to the model builder...
builder.ComplexType<B>();
I can then pass in nested data of this type on Patch, but now my Get doesn't work, because it says you can't expand to complex types, only navigational types.
So, it only works one way or the other. Any ideas on how I can accomplish something like this for both situations at the same time?
Thanks!
You can use the $ref to set up the link between entities.
For example:
POST ~/As to create a new A to As, from the response, you can get the location Id. So, you can get the key of new A
POST ~/Bs to create a new B to Bs, from the response, you can get the location Id. So, you can get the id (uri) of new B.
Then, you can use the $ref to create a link between the new A and the new B.
For the $ref, you can refer to the sample code here.
I have the table Users and the table Posts.
---Users---
id
name
---Posts---
id
text
User
How do I get the list of users, including the posts? I know how to get the list of posts with the users, because the pointer of the user is in that table. But the users does not have any pointers to posts.
What you want will be a lot of requests. You can easily query for (and paginate) the users. Then, for each user, you need to make another (paginated) request to find Posts with a pointer to that user. For that use whereKey:equalTo: with the bame of the user column on the Post and the current user instance.
Do you have a list of users already, and need to get all of their posts? If so, use the whereKey:containedIn: method. You can also create a query on users that pulls all the users you want to pull the posts for, and then rather than running the query, you create a second query on your posts objects and use whereKey:matchesQuery: which means that the object referenced in the Key is an object that would be returned by the query you pass in. So it'll return all the posts relevant to the users that would be returned from the initial query.
When you run this query, you may want to look into the query.each() method as an alternative to query.find(). query.find() is limited to 1000 results, query.each goes through every single result. This could be a problem when you scale, though, as cloud methods have a 15 second timer, and before/after save triggers have a 3 second timer.
Right now I have a server that formats my data exactly how restkit wants it, and restkit just takes it and directly maps it to coredata.
This works fine, but when I start to accumulate a lot of data it becomes slow.
For example, I have one object called "stories" and each story contains an array of "posts". each time a new "post" gets added, I regenerate the "story" object to which the new post belongs to, and return the story object to the user for restkit to map. As a story starts to accumulate many posts, this process becomes very slow for restkit. I would prefer a way to just send back new posts, and then tell restkit "hey, add this post to the array of posts on this story", which is in contrast to what I do now which is more like "replace this story with this one I just returned, which includes all posts including any new or updated ones".
Is this possible within restkit? Am I better served just manipulating core data myself to support updates?
Yes, it's possible.
You can look at 'foreign key mapping' to connect your new posts to the existing story. The most important part is to set the relationship assignment type to Union because the default is replace.
I'm making an "API" call for getting a list of "MyMusic" album. It returns array of music ids and those ids are linked with another table. So in order to get music details like name etc. I need to make separate "API" calls with id.
What is the recommended way to make "API" calls to fill my array with music details.
Depends on if the API can return multiple id's. Can you send a JSON-array to the API and get an array in return? If not, it looks like you have to send the id's one at a time.
If you don't for some reason NEED to use the REST api (which it seems you are doing now), then in your first query use includeKey on the field that contains the IDs. If this field is a Pointer to another table, this will make sure the full objects are returned in the first query instead of just the pointers.
We're currently interfacing with an OData database, over HTTP.
I need to POST objects (i.e. create them). This works, but how can I get the identifier of the created object?
Comparing this to SQL, how could I get the last insert ID?
OData posts responses contain the object that was created. So, you should be able to parse the response and find out the key(ID). The $metadata document would tell you which properties are the keys.