{"issue":{"pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"state":"open","user":{"avatar_url":"https://secure.gravatar.com/avatar/8412f5fb81116f67a43d6961fc50a5d5?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"8412f5fb81116f67a43d6961fc50a5d5","url":"https://api.github.com/users/mhermans","login":"mhermans","id":41405},"milestone":{"state":"open","open_issues":15,"url":"https://api.github.com/repos/hmarr/mongoengine/milestones/2","due_on":null,"creator":{"avatar_url":"https://secure.gravatar.com/avatar/630e114bb1f79c0924103b96921227c2?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"630e114bb1f79c0924103b96921227c2","url":"https://api.github.com/users/rozza","login":"rozza","id":420},"title":"0.6","description":"Multi db support","number":2,"closed_issues":20,"created_at":"2011-06-21T09:49:55Z"},"updated_at":"2011-11-10T18:10:06Z","assignee":null,"labels":[],"closed_at":null,"comments":2,"url":"https://api.github.com/repos/hmarr/mongoengine/issues/349","body":"With the introduction of cascading saves, I'm interested in the possibility of saving all referenced Documents, regardless of whether they already exist or not.\r\n\r\nCurrently, you get a \"You can only reference documents once they have been saved to the database\" validation error if some of the referenced Documents are not previously saved (see [here](http://pastie.org/2805095) for a basic example).\r\n\r\nFeel free to close if this request is to specific/difficult, or if there is an easy workaround that I'm missing.\r\n\r\nMy use-case: I parse [XBRL](http://en.wikipedia.org/wiki/XBRL) records, which results per record in one Organisation object and a lot of referenced Organisation, Person, Location, etc. objects. Some of which are loaded/existing, some of which are newly created from that record, and all of them can be referencing each other. \r\n\r\nIt would be easier if I could just save() the main Organisation object, recursively saving the referenced objects without worrying/tracking which referenced objects are new.","html_url":"https://github.com/hmarr/mongoengine/issues/349","title":"Cascading saves only saves previously existing Documents","number":349,"id":2134460,"created_at":"2011-11-03T16:40:31Z"},"action":"created","comment":{"user":{"avatar_url":"https://secure.gravatar.com/avatar/03ef913aa3864d0348ba9779a96937cd?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"03ef913aa3864d0348ba9779a96937cd","url":"https://api.github.com/users/cybertoast","login":"cybertoast","id":16698},"updated_at":"2011-11-10T18:10:06Z","url":"https://api.github.com/repos/hmarr/mongoengine/issues/comments/2698797","body":"+1\r\nIn the case of get_or_create() or even a save() that references an existing document, this would be helpful. The use case is as below:\r\n\r\n```python\r\nclass User(Document):\r\n    name = StringField(required=True)\r\n    title = StringField()\r\n    dob = DatetimeField(required=True)\r\n\r\nfor user in Users.objects.only(*['name', 'title'])\r\n    searchTerms = SearchTerms.objects.get_or_create(link_to=user, text=user.name)\r\n    # The above will cause an exception since validate() will fail due to dob missing in the only() list,\r\n    # even though it might exist on the user object\r\n\r\n```\r\n\r\nThe proposed solution (cascade) would solve this because the only() will not cause a validate() error:\r\n\r\n```python\r\nfor user in Users.objects.only(*['name', 'title'])\r\n    searchTerms = SearchTerms.objects.get_or_create(link_to=user, text=user.name, write_options={'cascade':False})\r\n    # Will not have an exception since no cascading save\r\n```\r\n\r\nSo the `cascade` option needs to also be passed to be passable to:\r\n* get_or_create()\r\n* update()\r\n","id":2698797,"created_at":"2011-11-10T18:10:06Z"}}