{"action":"created","issue":{"url":"https://api.github.com/repos/neumino/thinky/issues/184","labels_url":"https://api.github.com/repos/neumino/thinky/issues/184/labels{/name}","comments_url":"https://api.github.com/repos/neumino/thinky/issues/184/comments","events_url":"https://api.github.com/repos/neumino/thinky/issues/184/events","html_url":"https://github.com/neumino/thinky/issues/184","id":58489416,"number":184,"title":"saveAll() with an array of string object Ids instead of objects?","user":{"login":"mindjuice","id":934638,"avatar_url":"https://avatars.githubusercontent.com/u/934638?v=3","gravatar_id":"","url":"https://api.github.com/users/mindjuice","html_url":"https://github.com/mindjuice","followers_url":"https://api.github.com/users/mindjuice/followers","following_url":"https://api.github.com/users/mindjuice/following{/other_user}","gists_url":"https://api.github.com/users/mindjuice/gists{/gist_id}","starred_url":"https://api.github.com/users/mindjuice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mindjuice/subscriptions","organizations_url":"https://api.github.com/users/mindjuice/orgs","repos_url":"https://api.github.com/users/mindjuice/repos","events_url":"https://api.github.com/users/mindjuice/events{/privacy}","received_events_url":"https://api.github.com/users/mindjuice/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-02-22T04:09:36Z","updated_at":"2015-02-23T03:44:47Z","closed_at":"2015-02-23T03:44:47Z","body":"Hi all,\r\n\r\nJust started working with Thinky & RethinkDB last week and am really liking it so far!  Very nice work!\r\n\r\nI'm working on two models now, Class and User with the following properties:\r\n  * A User can attend multiple Classes\r\n  * A Class can contain multiple Users\r\n\r\nI've modelled it with a set of reciprocal **hasAndBelongsToMany** relationships in both directions as below:\r\n\r\n    User.hasAndBelongsToMany(Class, 'classesEnrolled', 'id', 'id');\r\n    Class.hasAndBelongsToMany(User, 'students', 'id', 'id');\r\n\r\nWhen I want to put a student User into a class, I build an update JSON object on the client side that looks like this:\r\n\r\n    { classesEnrolled: [ '76c4bdc5-d9e5-4b03-98d1-9f39a3ef13db' ],\r\n      id: '7f75a866-0c50-425f-86b5-984b106aebf0' }\r\n\r\nI do a **get().getJoin()** on that **id**, and call **doc.merge()** to merge in the **classesEnrolled** array and then call **saveAll()**, but I get the following error:\r\n\r\n    TypeError: Object 76c4bdc5-d9e5-4b03-98d1-9f39a3ef13db has no method 'isSaved'\r\n\r\nAfter thinking about this for a while and trying to figure out what was wrong, I looked more closely at your examples and noticed that you only ever show saving a joined document after setting a reference to another joined document.  The error seems to mean that a string object doesn't have an **isSaved()** method (of course it doesn't).\r\n\r\nSo that's a long-winded way of getting around to asking, is there any way to have Thinky lookup the objects by id string and then establish the relationships for me?  Otherwise, for every object that has these types of relationships, I have to write code to see if one of the joined fields is being saved, asynchronously lookup each of the elements in the array, build up another array with object references instead of strings, and then finally do **saveAll()**.  That would be pretty tedious and error prone.\r\n\r\nThanks."},"comment":{"url":"https://api.github.com/repos/neumino/thinky/issues/comments/75485958","html_url":"https://github.com/neumino/thinky/issues/184#issuecomment-75485958","issue_url":"https://api.github.com/repos/neumino/thinky/issues/184","id":75485958,"user":{"login":"neumino","id":1461947,"avatar_url":"https://avatars.githubusercontent.com/u/1461947?v=3","gravatar_id":"","url":"https://api.github.com/users/neumino","html_url":"https://github.com/neumino","followers_url":"https://api.github.com/users/neumino/followers","following_url":"https://api.github.com/users/neumino/following{/other_user}","gists_url":"https://api.github.com/users/neumino/gists{/gist_id}","starred_url":"https://api.github.com/users/neumino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neumino/subscriptions","organizations_url":"https://api.github.com/users/neumino/orgs","repos_url":"https://api.github.com/users/neumino/repos","events_url":"https://api.github.com/users/neumino/events{/privacy}","received_events_url":"https://api.github.com/users/neumino/received_events","type":"User","site_admin":false},"created_at":"2015-02-23T03:44:47Z","updated_at":"2015-02-23T03:44:47Z","body":"It's also released in 1.16.4.\r\nLet me know if you have more questions @mindjuice :)"}}