As described here , I would like to save the Book objects in a separate ref and keep its id value inside the books User property
Users: user_id:121jhg12h12 email: " john@doe.com " name: "John Doe" profile_pic_path: "https://...". language: "en" exp_points: 1284 friends: [user_id] books: [[book_id, status, current_page, start_date, finish_date]] badges: [[badge_id, get_date]] Books: book_id: 3213jhg21 title: "For whom the bell tolls" author: "Ernest Hemingway" language: "en" pages_count: 690 ISBN: "21hjg1" year: 2007
Whenever I add a book inside the application
self.ref!.child("Books").childByAutoId().setValue(["title": arrayOfNames[0] as! NSString, "author": arrayOfNames[1] as! NSString , "pages_count":arrayOfNames[2] as! NSString])
The book object is created in the ref book, but I would like to immediately add its identifier to the user array of users.
Could this be done in some elegant way, instead of requesting a book, getting its identifier and adding it to the array?
If not, how can I request the identifier of the object that was just created?
Perhaps I should not use AutoId mode and create a unique identifier for each object on my own in the application?
DCDC source share