I have a rest webservice that gets me the a json response in the following structure :
{
"Categories": [
{
"category_id":1,
"category_name":"category 1"
},
{
"category_id":2,
"category_name":"category 2"
}
],
"Products":[
{
"product_id":1,
"product_name":"Product 1",
"category_id":1
},
{
"product_id":2,
"product_name":"Product 2",
"category_id":1
},
{
"product_id":3,
"product_name":"Product 3",
"category_id":2
}
]
}
I am creating a Core data model for my iOS application in which i can save this data as you can see below .
The problem is how can I use the relationships that I have created in my core data model to map this data?
The silliest idea that comes to my mind is to search for each product's category based on the category id and then set it like
Product.category = category [i] , but there got to be a easier way to do this.
Based on your use of ObjectMapper you will need to make the connections yourself using your 'silly idea (TM)'. You should look at doing the fetch as a batch and sorting the results to minimise calls to Core Data and to make the mapping simple.
If you chose to use RestKit then you could just configure the mappings for the objects and the identities used to link them and RestKit will do the lifting work. It could be a bit of work for you...
Related
This question already has an answer here:
Speed up fetching posts for my social network app by using query instead of observing a single event repeatedly
(1 answer)
Closed 1 year ago.
I am new to Firebase. The following is my database's structure.
{
"dvdStores": {
"store1": {
"movies": {
"0": "Don't Look Up",
"1": "Top Gun"
}
},
"store2": {
"movies": {
"0": "Jungle Book",
"1": "Taken"
}
},
"store3": {
"movies": {
"0": "The Matrix",
"1": "Home Alone"
}
},
"store4": {
"movies": {
"0": "The Lion King"
}
}
}
}
Can I get all the movies corresponding to multiple keys in a single query?
I would e.g. want to get all the movies corresponding to keys store1 and store4. Can this be done in a single query?
Thanks in advance :)
This is not possible. You must request them each individually. All queries for a node always get the entire node, including all of its nested children. Children cannot be selectively included or excluded.
It's worth noting also that there is not much overhead in making multiple requests. The data for each query is pipelined over a single socket connection, so as long as you keep that connected saturated with requests, you are not losing very much perceived performance.
I implemented with Graph API several calls to create a document set.
I followed the answer posted here concerning the possibility of creating a DocumentSet in SharePoint here : Is it possible to create a project documentset using graph API?
For this i followed those steps :
1. Getting the library driveId :
`GET https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}?$expand=drive`
2. Creating the folder:
POST https://graph.microsoft.com/v1.0/drives/${driveId}/root/children
I have to pass an object:
{
"name": ${nameOfTheFolder},
"folder": {},
}
3. Getting the Sharepoint itemId:
4. Updating the document library:
`PATCH https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}/items/${sharepointIds.listItemId}`
and passing a body:
{
"contentType": {
"id": "content-type-id-of-the-document-set"
},
"fields": {
//whatever fields you want to set
}
}
I have questions concerning the folder creation and the updating:
What is expected in the folder object ?
{
"name": ${nameOfTheFolder},
"folder": {},
}
Concerning the path step:
{
"contentType": {
"id": "content-type-id-of-the-document-set"
},
"fields": {
//whatever fields you want to set
}
}
I have several questions :
Let's consider i have a document type called invoices. Which id is expected for document type id ?
finally how do i pass the fields ? let's say i want to pass 3 fields : invoiceId, claimId, clientId.
Graph API is great but some more information would be helpful. thanks !
I have questions concerning the folder creation and the updating: What is expected in the folder object ?
The folder object (sent as {}) is there to tell graph API that you are creating a folder and not a file. It is a property of the drive item
Let's consider i have a document type called invoices. Which id is expected for document type id ?
This is the id contentType subfield of the list item you are patching
ally how do i pass the fields ? let's say i want to pass 3 fields : invoiceId, claimId, clientId.
You just pass them with repective values like below. See Update listItem
{
"invoiceId": "value",
"claimId": "value"
...
}
One point I didn't express correctly was to know what id is expected here :
{
"contentType": {
"id": "content-type-id-of-the-document-set"
},
"fields": {
//whatever fields you want to set
}
}
I retrieved the different content types of my site by calling this kind of URL and check if the content type exists.
https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}/contentTypes
From the result i retrieve in a Value object the id.
The id looks like this :
0x0120D5200082903AB771604546844DB2AC483D905B00E58445A7D..........
In modern SharePoint, you can also get the Content Type ID from the UI by browsing to SharePoint Site > Site Settings > Site content types > <ContentTypeName> > Content Type ID.
Content Type ID
Not sure if this is easier than via graph, but it's another option at least.
I'm relatively new to CouchDB (more specifically Cloudant if it matters) and I'm having a hard time wrapping my head around something.
Assume the following (simplified) document examples:
{ "docType": "school", "_id": "school1", "state": "CA" }
{ "docType": "teacher", "_id": "teacher1", "age": "40", "school": "school1" }
I want to find all the teachers aged $age (eg. 40) in state $state (eg. CA).
Views only consider one document at a time; that is queries can't directly combine data from different documents. You can query across multiple fields in the same document using Cloudant Query. You can write a selector directly in the Cloudant dashboard. Something like
"selector": {
"age": {
"$gte": 40
},
"state": {
"$eq": "CA"
}
}
See https://cloud.ibm.com/docs/services/Cloudant/tutorials?topic=cloudant-creating-an-ibm-cloudant-query
with the full reference here: https://cloud.ibm.com/docs/services/Cloudant/tutorials?topic=cloudant-query
You could also use a so-called linked document to emulate basic joins, as outlined in the CouchDB docs https://docs.couchdb.org/en/stable/ddocs/views/joins.html
I'm creating an Events app which needs to pull data from a JSON web service to get information about the artists and the shows that are being played. The data will be used to display the line up of artists (a to z) on one view, artists by date and time on another view, and artists by location and sorted by date/time on a third view. We will also allow the user to add shows to their schedule.
The JSON data is similar to this:
Artists feed:
[
{
"artists": {
"3": {
"id": "3",
"title": "Kendrick Lamar",
"subtitle": null,
"imageURL":
"//goevent-images.s3.amazonaws.com/.../web/artist_3_20140331112744_d57b5a70.jpg",
"gcInfo": "artist$kendrick-lamar/3",
"shows": [ {
"id": 153,
"venueTitle": "Sapporo scene",
"formattedDate": "Sunday, August 31",
"date": "2014-08-31",
"title": "Kendrick Lamar"
}
],
"tags": ",8,159,164,",
"color": "#00a0a0",
"dates": [
"2014-08-31"
]
},... },
]
Shows feed:
[
{
"items": {
"197": {
"id": 197,
"title": "Arcade Fire",
"type": "artist",
"dateStart": "2014-08-30",
"timeStart": "16:00:00",
"formattedTimeStart": " 4:00 PM",
"gcInfo": "artist$arcade-fire/127",
"venueId": "1",
"tags": ",80,",
"color": "#337FC3"
}
}
]
Shows and artists will have a many to many relationship. I'll also need to create an entity/table for storing the user's shows that will be added to their personal schedule.
Bands/shows do have the possibility of being removed from the feed, so I think I'll likely need to clear out the artists and shows entities/tables before importing. I'm worried this will break the relationship to the user's scheduled shows.
I also need to download as much of the high-level data as possible upfront so that the app can be used offline as well.
So my question is:
What's the best approach to importing and storing the data for this?
“Best” is subjective. As I understand it, Core Data uses SQLite under the covers, so it's really more a matter of what you're comfortable with.
Have you used Core Data before? If so, use that.
Have you used an SQL Database before? if so, use SQLite.
If you're starting from square one, I supposed I'd recommend Core Data.
Here are a few links to get you started:
Data Management in iOS by Apple
Core Data Programming Guide from Apple.
Core Data Tutorial for iOS: Getting Started
How to Use SQLite to Manage Data in iOS Apps
SQLite Tutorial for iOS: Creating and Scripting
I am quite new to RestKit. I know that the Object Mapping of Restkit is very powerful. However, in some case, I just want to map to a simple variable. For example, take a look at the following response:
{
"response": 400,
"result": {
"error_message": "Invalid session token"
}
}
I just want to know the value of "response" or "error_message". It's quite wasteful to create 2 classes "response", and "result", since these classes have only few fields.
Any recommendation is welcome.
You can create a single class with response and message properties, then use mappings:
#"response" : #"response",
#"result.error_message" : #"message"
Or you can just map into a dictionary for error responses and then use the keypath to access the message.