{"action":"created","comment":{"url":"https://api.github.com/repos/zdennis/activerecord-import/pulls/comments/25136043","id":25136043,"diff_hunk":"@@ -230,8 +230,49 @@ def supports_on_duplicate_key_update?\n     # This returns an object which responds to +failed_instances+ and +num_inserts+.\n     # * failed_instances - an array of objects that fails validation and were not committed to the database. An empty array if no validation is performed.\n     # * num_inserts - the number of insert statements it took to import the data\n-    def import( *args )\n-      options = { :validate=>true, :timestamps=>true }\n+    def import(*args)\n+      if args.first.is_a?( Array ) and args.first.first.is_a? ActiveRecord::Base\n+        options = {}\n+        options.merge!( args.pop ) if args.last.is_a?(Hash)\n+\n+        models = args.first # the import argument parsing is too tangled for me ... I only want to prove the concept of saving recursively\n+        result = import_helper(models, options)\n+        # now, for all the dirty associations, collect them into a new set of models, then recurse.\n+        # notes:\n+        #    does not handle associations that reference themselves\n+        #    assumes that the only associations to be saved are marked with :autosave\n+        #    should probably take a hash to associations to follow.\n+        hash={}\n+        models.each {|model| add_objects(hash, model) }\n+\n+        hash.each_pair do |class_name, assocs|\n+          assocs.each_pair do |assoc_name, subobjects|\n+            subobjects.first.class.import(subobjects, options) unless subobjects.empty?\n+          end\n+        end\n+        result\n+      else\n+        import_helper(*args)\n+      end\n+    end\n+\n+    def add_objects(hash, parent)","path":"lib/activerecord-import/import.rb","position":41,"original_position":41,"commit_id":"5828103db4887c82a929c288bf616aa69e7f746c","original_commit_id":"5828103db4887c82a929c288bf616aa69e7f746c","user":{"login":"johnnaegle","id":1682292,"avatar_url":"https://avatars.githubusercontent.com/u/1682292?v=3","gravatar_id":"","url":"https://api.github.com/users/johnnaegle","html_url":"https://github.com/johnnaegle","followers_url":"https://api.github.com/users/johnnaegle/followers","following_url":"https://api.github.com/users/johnnaegle/following{/other_user}","gists_url":"https://api.github.com/users/johnnaegle/gists{/gist_id}","starred_url":"https://api.github.com/users/johnnaegle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnnaegle/subscriptions","organizations_url":"https://api.github.com/users/johnnaegle/orgs","repos_url":"https://api.github.com/users/johnnaegle/repos","events_url":"https://api.github.com/users/johnnaegle/events{/privacy}","received_events_url":"https://api.github.com/users/johnnaegle/received_events","type":"User","site_admin":false},"body":"Will take a look tomorrow\n\nOn Sun, Feb 22, 2015 at 12:42 PM, Zach Dennis <notifications@github.com>\nwrote:\n\n> In lib/activerecord-import/import.rb\n> <https://github.com/zdennis/activerecord-import/pull/178#discussion_r25135051>\n> :\n>\n> > +        #    should probably take a hash to associations to follow.\n> > +        hash={}\n> > +        models.each {|model| add_objects(hash, model) }\n> > +\n> > +        hash.each_pair do |class_name, assocs|\n> > +          assocs.each_pair do |assoc_name, subobjects|\n> > +            subobjects.first.class.import(subobjects, options) unless subobjects.empty?\n> > +          end\n> > +        end\n> > +        result\n> > +      else\n> > +        import_helper(*args)\n> > +      end\n> > +    end\n> > +\n> > +    def add_objects(hash, parent)\n>\n> We'll want to hide this method and import_helper in the Import module.\n> Right now it looks like it's being added to ActiveRecord::Base as a class\n> method. We should only add the public methods that we want to expose to a\n> user there so we don't unnecessarily pollute or add potential conflicts w/\n> other things on ActiveRecord::Base.\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/zdennis/activerecord-import/pull/178/files#r25135051>.\n>\n","created_at":"2015-02-22T20:25:51Z","updated_at":"2015-02-22T20:25:51Z","html_url":"https://github.com/zdennis/activerecord-import/pull/178#discussion_r25136043","pull_request_url":"https://api.github.com/repos/zdennis/activerecord-import/pulls/178","_links":{"self":{"href":"https://api.github.com/repos/zdennis/activerecord-import/pulls/comments/25136043"},"html":{"href":"https://github.com/zdennis/activerecord-import/pull/178#discussion_r25136043"},"pull_request":{"href":"https://api.github.com/repos/zdennis/activerecord-import/pulls/178"}}},"pull_request":{"url":"https://api.github.com/repos/zdennis/activerecord-import/pulls/178","id":29731364,"html_url":"https://github.com/zdennis/activerecord-import/pull/178","diff_url":"https://github.com/zdennis/activerecord-import/pull/178.diff","patch_url":"https://github.com/zdennis/activerecord-import/pull/178.patch","issue_url":"https://api.github.com/repos/zdennis/activerecord-import/issues/178","number":178,"state":"open","locked":false,"title":"return the inserted ids for postgres bulk insert","user":{"login":"johnnaegle","id":1682292,"avatar_url":"https://avatars.githubusercontent.com/u/1682292?v=3","gravatar_id":"","url":"https://api.github.com/users/johnnaegle","html_url":"https://github.com/johnnaegle","followers_url":"https://api.github.com/users/johnnaegle/followers","following_url":"https://api.github.com/users/johnnaegle/following{/other_user}","gists_url":"https://api.github.com/users/johnnaegle/gists{/gist_id}","starred_url":"https://api.github.com/users/johnnaegle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnnaegle/subscriptions","organizations_url":"https://api.github.com/users/johnnaegle/orgs","repos_url":"https://api.github.com/users/johnnaegle/repos","events_url":"https://api.github.com/users/johnnaegle/events{/privacy}","received_events_url":"https://api.github.com/users/johnnaegle/received_events","type":"User","site_admin":false},"body":"per #104 and #105, I've rebased the commits onto the latest zdennis master and got the adapter tests working for mysql, postgres and sqlite3.\r\n\r\ninsert_many now returns the number of imports and the ids of the objects inserted (if the adapter provides them).  Those ids are then set on the model and the model is marked as clean.  For auto-save associations, a recursive bulk import is performed. There are postgresql adapter specific tests that show the ids getting set and recursive import of autosave associations.\r\n","created_at":"2015-02-20T21:11:15Z","updated_at":"2015-02-22T20:25:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"09d9b7485ddea788e23c989c7f03a77e12d2fdc8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/zdennis/activerecord-import/pulls/178/commits","review_comments_url":"https://api.github.com/repos/zdennis/activerecord-import/pulls/178/comments","review_comment_url":"https://api.github.com/repos/zdennis/activerecord-import/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zdennis/activerecord-import/issues/178/comments","statuses_url":"https://api.github.com/repos/zdennis/activerecord-import/statuses/5828103db4887c82a929c288bf616aa69e7f746c","head":{"label":"GoodMeasuresLLC:set_ids_in_bulk_import","ref":"set_ids_in_bulk_import","sha":"5828103db4887c82a929c288bf616aa69e7f746c","user":{"login":"GoodMeasuresLLC","id":4303282,"avatar_url":"https://avatars.githubusercontent.com/u/4303282?v=3","gravatar_id":"","url":"https://api.github.com/users/GoodMeasuresLLC","html_url":"https://github.com/GoodMeasuresLLC","followers_url":"https://api.github.com/users/GoodMeasuresLLC/followers","following_url":"https://api.github.com/users/GoodMeasuresLLC/following{/other_user}","gists_url":"https://api.github.com/users/GoodMeasuresLLC/gists{/gist_id}","starred_url":"https://api.github.com/users/GoodMeasuresLLC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoodMeasuresLLC/subscriptions","organizations_url":"https://api.github.com/users/GoodMeasuresLLC/orgs","repos_url":"https://api.github.com/users/GoodMeasuresLLC/repos","events_url":"https://api.github.com/users/GoodMeasuresLLC/events{/privacy}","received_events_url":"https://api.github.com/users/GoodMeasuresLLC/received_events","type":"Organization","site_admin":false},"repo":{"id":11153635,"name":"activerecord-import","full_name":"GoodMeasuresLLC/activerecord-import","owner":{"login":"GoodMeasuresLLC","id":4303282,"avatar_url":"https://avatars.githubusercontent.com/u/4303282?v=3","gravatar_id":"","url":"https://api.github.com/users/GoodMeasuresLLC","html_url":"https://github.com/GoodMeasuresLLC","followers_url":"https://api.github.com/users/GoodMeasuresLLC/followers","following_url":"https://api.github.com/users/GoodMeasuresLLC/following{/other_user}","gists_url":"https://api.github.com/users/GoodMeasuresLLC/gists{/gist_id}","starred_url":"https://api.github.com/users/GoodMeasuresLLC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoodMeasuresLLC/subscriptions","organizations_url":"https://api.github.com/users/GoodMeasuresLLC/orgs","repos_url":"https://api.github.com/users/GoodMeasuresLLC/repos","events_url":"https://api.github.com/users/GoodMeasuresLLC/events{/privacy}","received_events_url":"https://api.github.com/users/GoodMeasuresLLC/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoodMeasuresLLC/activerecord-import","description":"Extraction of the ActiveRecord::Base#import functionality from ar-extensions for Rails 3 and beyon","fork":true,"url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import","forks_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/forks","keys_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/teams","hooks_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/hooks","issue_events_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/issues/events{/number}","events_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/events","assignees_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/assignees{/user}","branches_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/branches{/branch}","tags_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/tags","blobs_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/statuses/{sha}","languages_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/languages","stargazers_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/stargazers","contributors_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/contributors","subscribers_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/subscribers","subscription_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/subscription","commits_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/contents/{+path}","compare_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/merges","archive_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/downloads","issues_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/issues{/number}","pulls_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/pulls{/number}","milestones_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/milestones{/number}","notifications_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/labels{/name}","releases_url":"https://api.github.com/repos/GoodMeasuresLLC/activerecord-import/releases{/id}","created_at":"2013-07-03T15:03:05Z","updated_at":"2015-02-11T21:49:03Z","pushed_at":"2015-02-21T03:53:40Z","git_url":"git://github.com/GoodMeasuresLLC/activerecord-import.git","ssh_url":"git@github.com:GoodMeasuresLLC/activerecord-import.git","clone_url":"https://github.com/GoodMeasuresLLC/activerecord-import.git","svn_url":"https://github.com/GoodMeasuresLLC/activerecord-import","homepage":"http://www.continuousthinking.com","size":4172,"stargazers_count":6,"watchers_count":6,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":0,"forks":11,"open_issues":0,"watchers":6,"default_branch":"master"}},"base":{"label":"zdennis:master","ref":"master","sha":"2e8f19ee9aefc9e43eebf4c91697e918d11b8747","user":{"login":"zdennis","id":967,"avatar_url":"https://avatars.githubusercontent.com/u/967?v=3","gravatar_id":"","url":"https://api.github.com/users/zdennis","html_url":"https://github.com/zdennis","followers_url":"https://api.github.com/users/zdennis/followers","following_url":"https://api.github.com/users/zdennis/following{/other_user}","gists_url":"https://api.github.com/users/zdennis/gists{/gist_id}","starred_url":"https://api.github.com/users/zdennis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zdennis/subscriptions","organizations_url":"https://api.github.com/users/zdennis/orgs","repos_url":"https://api.github.com/users/zdennis/repos","events_url":"https://api.github.com/users/zdennis/events{/privacy}","received_events_url":"https://api.github.com/users/zdennis/received_events","type":"User","site_admin":false},"repo":{"id":558790,"name":"activerecord-import","full_name":"zdennis/activerecord-import","owner":{"login":"zdennis","id":967,"avatar_url":"https://avatars.githubusercontent.com/u/967?v=3","gravatar_id":"","url":"https://api.github.com/users/zdennis","html_url":"https://github.com/zdennis","followers_url":"https://api.github.com/users/zdennis/followers","following_url":"https://api.github.com/users/zdennis/following{/other_user}","gists_url":"https://api.github.com/users/zdennis/gists{/gist_id}","starred_url":"https://api.github.com/users/zdennis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zdennis/subscriptions","organizations_url":"https://api.github.com/users/zdennis/orgs","repos_url":"https://api.github.com/users/zdennis/repos","events_url":"https://api.github.com/users/zdennis/events{/privacy}","received_events_url":"https://api.github.com/users/zdennis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zdennis/activerecord-import","description":"Extraction of the ActiveRecord::Base#import functionality from ar-extensions for Rails 3 and beyon","fork":false,"url":"https://api.github.com/repos/zdennis/activerecord-import","forks_url":"https://api.github.com/repos/zdennis/activerecord-import/forks","keys_url":"https://api.github.com/repos/zdennis/activerecord-import/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zdennis/activerecord-import/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zdennis/activerecord-import/teams","hooks_url":"https://api.github.com/repos/zdennis/activerecord-import/hooks","issue_events_url":"https://api.github.com/repos/zdennis/activerecord-import/issues/events{/number}","events_url":"https://api.github.com/repos/zdennis/activerecord-import/events","assignees_url":"https://api.github.com/repos/zdennis/activerecord-import/assignees{/user}","branches_url":"https://api.github.com/repos/zdennis/activerecord-import/branches{/branch}","tags_url":"https://api.github.com/repos/zdennis/activerecord-import/tags","blobs_url":"https://api.github.com/repos/zdennis/activerecord-import/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zdennis/activerecord-import/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zdennis/activerecord-import/git/refs{/sha}","trees_url":"https://api.github.com/repos/zdennis/activerecord-import/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zdennis/activerecord-import/statuses/{sha}","languages_url":"https://api.github.com/repos/zdennis/activerecord-import/languages","stargazers_url":"https://api.github.com/repos/zdennis/activerecord-import/stargazers","contributors_url":"https://api.github.com/repos/zdennis/activerecord-import/contributors","subscribers_url":"https://api.github.com/repos/zdennis/activerecord-import/subscribers","subscription_url":"https://api.github.com/repos/zdennis/activerecord-import/subscription","commits_url":"https://api.github.com/repos/zdennis/activerecord-import/commits{/sha}","git_commits_url":"https://api.github.com/repos/zdennis/activerecord-import/git/commits{/sha}","comments_url":"https://api.github.com/repos/zdennis/activerecord-import/comments{/number}","issue_comment_url":"https://api.github.com/repos/zdennis/activerecord-import/issues/comments{/number}","contents_url":"https://api.github.com/repos/zdennis/activerecord-import/contents/{+path}","compare_url":"https://api.github.com/repos/zdennis/activerecord-import/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zdennis/activerecord-import/merges","archive_url":"https://api.github.com/repos/zdennis/activerecord-import/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zdennis/activerecord-import/downloads","issues_url":"https://api.github.com/repos/zdennis/activerecord-import/issues{/number}","pulls_url":"https://api.github.com/repos/zdennis/activerecord-import/pulls{/number}","milestones_url":"https://api.github.com/repos/zdennis/activerecord-import/milestones{/number}","notifications_url":"https://api.github.com/repos/zdennis/activerecord-import/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zdennis/activerecord-import/labels{/name}","releases_url":"https://api.github.com/repos/zdennis/activerecord-import/releases{/id}","created_at":"2010-03-12T05:06:53Z","updated_at":"2015-02-22T18:37:48Z","pushed_at":"2015-02-22T18:37:48Z","git_url":"git://github.com/zdennis/activerecord-import.git","ssh_url":"git@github.com:zdennis/activerecord-import.git","clone_url":"https://github.com/zdennis/activerecord-import.git","svn_url":"https://github.com/zdennis/activerecord-import","homepage":"http://www.continuousthinking.com","size":4911,"stargazers_count":935,"watchers_count":935,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":290,"mirror_url":null,"open_issues_count":67,"forks":290,"open_issues":67,"watchers":935,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zdennis/activerecord-import/pulls/178"},"html":{"href":"https://github.com/zdennis/activerecord-import/pull/178"},"issue":{"href":"https://api.github.com/repos/zdennis/activerecord-import/issues/178"},"comments":{"href":"https://api.github.com/repos/zdennis/activerecord-import/issues/178/comments"},"review_comments":{"href":"https://api.github.com/repos/zdennis/activerecord-import/pulls/178/comments"},"review_comment":{"href":"https://api.github.com/repos/zdennis/activerecord-import/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zdennis/activerecord-import/pulls/178/commits"},"statuses":{"href":"https://api.github.com/repos/zdennis/activerecord-import/statuses/5828103db4887c82a929c288bf616aa69e7f746c"}}}}