Parse.com afterSave trigger for object with array of other objects - parse-platform

I need to analyse some data after it has been uploaded to Parse and saved but the data is an object that contains an array of other objects...
Parent
-------
children : [Child]
I'm just not certain if the afterSave will trigger before all the children objects are uploaded and saved? Is it guaranteed that they will be there on the afterSave of the Parent object?
Thanks

In general the answer should be yes, they must always exist.
If it's an array of plain (not parse) objects then the data is directly there. If it's an array of parse objects (so an array of pointers) then the objects have to exist before they have ids and pointers can be generated for them. Same goes for a relationship to other parse objects.
Now, once the relationship to a parse object has been created it is not required that the parent is saved after the child - that is up to your code to guarantee if you need to. Indeed, it could just be that the child is saved and the parent isn't dirty so doesn't need to be saved...

Related

Save Related Documents In Mongo Reactive But Not In The Same Collection

I would like to know, how to save related documents in reactive mongo ?. Because I find a code that attempts to do the magic... But when it should save the related document in another collection, it serializes inside the "father" of the relationship let say... I know that in spring data reactive mongo, #DbRef doesnt have support... How could I save the data in a way that, if I query the collection, I see that the attributesare the name of the collection and the generated id instead all of the object attributes ?.
If the pic above is seen, you will see that the attribute "user" is saved as a nested document but not in the corresponding collection. Do I need to hook in another event ?.
I had put a listener onbeforeconvert to scan every time a save operation is to be applied and save the object... How to proceed ?... think I should verify if it has a related doc from another collection and if its nonnull... If the object doesnt have any attr l
Alike, then save it... if not continue the scanning... dunno

Key has no data from subclass of PFUser with reference pointer field

I need to update the current user and refetch every time the App launches so that I can grasp the most updated version of user object instead of using the one cached on the disk.
User.current()?.fetchInBackground(block: { (user, error) in
//simply using a fetchInBackground won't fetch the entire reference field store in
// the user collection. In the case of using PFQuery, we could simply include the key for
// reference field.
})
Do I have to do extra fetches for all those reference field and then update the current user's filed correspondingly?
Fetch only returns the data that is stored in your database. For a pointer, that is just a basic JSON object specifying it's a pointer, the class name, and the objectId of that object. In order to return this data, you'll instead want to use a Parse Query and include the field that you want. Include works with dot notation, so you could do something like objectAQuery.include("objectB.objectC") which will include all of the data of objectC stored as a pointer on objectB. That will not include all of objectB's data, if I'm not mistaken, though I can't say with certainty.
Finally, use query.get() to get an object with a specific objectId. This will throw an error if the object does not exist, though, so make sure you handle that appropriately. You could also use query equalTo on the objectId then call query.first(), but get would be more recommended.

Setting ID on child properties with EFBulkInsert

So im using EFBulkInsert https://efbulkinsert.codeplex.com/
The problem is I have child objects I need to set the ID of the inserted parent objects.
Previously after inserting the parents objects I've tried to rely on the context to return the id's and set them on the child objects - then use EFBulkInsert to insert the child objects - every now and then the context gets confused even after recreating the context and I get the wrong id on the child objects.
Does anyone have a good pattern / strategy for setting the parent id on the child object I should mention i'm doing this for a batch of 1000 parent objects. So I don't particularly want to get the id's from the database after SaveChanges for the parent object unless it's performant.
The best idea I have is to add two temporary columns, firtst to hold an original Id, and second to hold parentId. After bulk insert update proper columns. This method requires privilages to modify the table.
I had a similar problem when I couldn't modify database, so I set AutoDetectChangesEnabled and ValidateOnSaveEnabled to false, but results were not very satisfied.

how to use complex object to insert data in more than one table related "Entity Framework 4.1"

I would like to know is there any way to use complex type to insert data in more than one table
if I have a parent object has a collection of child object and I need to insert data in the parent and its child too
Example: This is the parent object "Video" and its Child VideoData Diagram
Please advice
EF will update all modified entities/properties automatically. So if you create a new VideoData, set it's language, and append it to the VideoDatas collection of a Video instance, then call
context.SaveChanges();
EF will add the VideoData to the db, setting the Language, then update the Video record. It walks up and down the graph saving any changes. You just need to make sure you are using context to get the entities in the first place so EF can track it.

issue with submitChanges() inserting unwanted records in linq

I am using LINQ to insert records in the database. I create these records and keep track of them using a List. Based on some logic, I delete some of the records by deleting from the List. (I am using the same DataContext object).
When I want to insert the records in the database, I do the corresponding linq table's InsertOnSubmit() followed by SubmitChanges() on datacontext object. LINQ inserts the deleted-from-List records too along with the ones that are present in the list.
example:
//list to keep track of records to insert
List list
// add the records to list
list.add(some records)
//deleted last 2 records
list.remove()
//call InsertAllOnSubmit on the linq table passing the list object with records to insert
linqTable.InsertAllOnSubmit(list)
//call SubmitChanges on datacontext object
datacontext.SubmitChanges()
I came across this msdn article Object States and Change-Tracking (LINQ to SQL)
You can explicitly request Inserts by
using InsertOnSubmit. Alternatively,
LINQ to SQL can infer Inserts by
finding objects connected to one of
the known objects that must be
updated. For example, if you add an
Untracked object to an
EntitySet(TEntity) or set an
EntityRef(TEntity) to an Untracked
object, you make the Untracked object
reachable by way of tracked objects in
the graph. While processing
SubmitChanges, LINQ to SQL traverses
the tracked objects and discovers any
reachable persistent objects that are
not tracked. Such objects are
candidates for insertion into the
database.
I guess the question boils down to this - how do I change the deleted objects' state to 'Untracked'?
I tried DeleteOnSubmit after I delete the objects from list but that gives an exception (Cannot remove an entity that has not been attached).
Can someone please point me to a solution? Thanks.
I would like to know if I can achieve this using LINQ only. (I know that I can use an stored proc and insert only the records in the list.)
I think that the elements of your list are not being removed, because the List.Remove method determines equality using the default equality comparer.
If you don't want to write a custom comparer, I recommend you to use the RemoveAll method, which receives a predicate as its first parameter to match the elements that will be removed from the list:
list.RemoveAll( e=> /*condition to remove the element*/ );
Or the RemoveAt method, that removes the element based on the specified index:
list.RemoveAt(0); // Delete first element

Resources