Edit core data entry - iphone

I have an application which is currently using and storing data in Core Data. My data moel looks like this:
My client has requested the ability to amend the Number (in Customer entity), or any of the attributes in 'Rooms' (except CustomerName).
I not sure where to start with this. I have done some googling and searching of questions, but cant seem to find a solution that fits my need.
Any help or sample code would be greatly appreciated.
Thanks
Sam

You can modify the number using the key value coding or by accessing its method directly
Customer* customer=[NSEntityDescription insertNewObjectForEntityForName:#"Customer" inManagedObjectContext:self.managedObjectContext];
customer.Number=[NSNumber numberWithInt:10];
if(![managedObjectContext save:&err])
NSLog(#"data cannot be saved");
You can access the Rooms entity in a similar way,which will be returned as NSSet* object.
Get the required object in that and modify the value in a similar fashion.

Related

insert msg object to mongodb (node-red)?

We're experimenting with storing data to a MongoDB by using node-red. As it is now, we can store data on the database, but it seems like only the 'msg.payload' is stored (as document) - and not the whole msg object. Which confuses us a little...
The flow is very simple and nothing much has really been done.
We actually dont need ALL data, but we wish to store payload but also metadata as a document to our collection on our database. We've tried searching for an answer to this, but couldn't find anything relevant on how to do this. Hopefully we can get some help on this forum.
Thanks in advance! (btw. we're using mongodb3 on node-red to store data)
The node you are using is working as intended.
The normal pattern for Node-RED is that the focus of any given node is the msg.payload entry, any other msg properties are considered to be meta data.
The simplest thing here would be to use the built in core change node to move the other fields you are interested in to be properties of the msg.payload object.

Parse.com data design

I have a question regarding how I should set up a database in Parse.com to have scalable queries. Below, is a picture of a simplified example of what I am trying to do.
So, as you can see with this idea, there is a user, that can create a ChatMessage or a MainMessage. The MainMessage also can have Comments posted to it. However, in a "feed" I will want to display both ChatMessages and MainMessages by dateCreated and I don't think that it will be an efficient query to get both ChatMessages and then MainMessages, and then sort.
To simplify, I have this...
As you can see, I made both ChatMessage and MainMessage from the first approach into a single Message with all of the attributes for both ChatMessage and MainMessage with the additional type attribute to distinguish between the two. Is it okay that in the new Message that will have multiple unused attributes based on type? Is that inefficient in Parse.com? Hypothetically, if MainMessage had way more (say 10) attributes than ChatMessage would this still be okay? I believe the second approach is better because I can simplify the query for the "feed". However, if there is anybody with anything to say on how I should be setting up the database, any comments are greatly appreciated. Thanks.

Trouble working with nested JSON objects on Objective-C

On my iPhone app, I'm getting this response from the server:
I need to save this data to disk, so it can be accessed while offline, and am doing it with NSKeyedArchiver.
I need to save each id_preguntawith its correspondent values, including the array respuestas, which has some objects, too.
How can I break this server response into more manageable data, so I can save it? My current approach is using NSMutableDictionary, but I just can't understand the logic behind this (I'm way too tired).
Thanks in advance.
If you were to serialize this into NSMutableDictionary you could just write the contents of the dictionary to a file. If you need to parse the data into objects (for whatever reason) or you want the general scalability and performance of a database you may want to look at this link to -> Core Data.
However; you did not specify in what form you want the data.
Frank
See these in NSDictionary class reference...
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag
and
+ (id)dictionaryWithContentsOfFile:(NSString *)path`

iPhone Data Structure and accessor code advice

I need a code based solution for storing the following data without using CoreData. Preferably I would be able to access each row based on it's index, and each data field using a key/pair perhaps?
The PHP equivalent of what I'm looking for would be something like;
echo $arr[0]['Image'];
Apple.png
The simplest way is to use an NSMutableArray of NSMutableDictionary objects.
NSMutableArray has a -writeToURL: method you can use to save it to disk.
You can use either plist, sqlite or Any other data storage take look at this link. and if you are using like Sqlite than select query will get the Apple.png.

MongoDB ObjectId foreign key implementation recommendation

I'm looking for a recommendation on how best to implement MongoDB foreign key ObjectId fields. There seem to be two possible options, either containing the nested _id field or without.
Take a look at the fkUid field below.
{'_id':ObjectId('4ee12488f047051590000000'), 'fkUid':{'_id':ObjectId('4ee12488f047051590000001')} }
OR
{'_id':ObjectId('4ee12488f047051590000000'), 'fkUid':ObjectId('4ee12488f047051590000001')} }
Any recommendations would be much appreciated.
I'm having a hard time coming up with any possible advantages for putting an extra field "layer" in there, so I would personally just store the ObjectId directly in fkUid.
I suggest to use default dbref implementation, that is described here http://www.mongodb.org/display/DOCS/Database+References and is compatible with most of specific language drivers.
If your question is about the naming of the field (what you have in the title), usually the convention is to name it after the object to which it refers.
The both ways that you have mentioned are one of the same meaning. But they have different kind of usages.
Storing fkUid like 'fkUid':{'_id':ObjectId('4ee12488f047051590000001')} an object has it's own pros. Let me give an example, Suppose there is a website where users can post images and view images posted by other users as well. But when showing the image the website also shows the name/username of the user. By using this way you also can store the details like 'fkUid':{'_id':ObjectId('4ee12488f047051590000001'), username: 'SOME_X'}. When you are getting details from the db you don't have to send a request again to get the username for the specific _id.
Where as in the second way 'fkUid':ObjectId('4ee12488f047051590000001')} } you have to send another request to the server only for getting the name/username and nothing else is useful from the same object.