{"action":"created","issue":{"url":"https://api.github.com/repos/percolatestudio/meteor-factory/issues/8","labels_url":"https://api.github.com/repos/percolatestudio/meteor-factory/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/percolatestudio/meteor-factory/issues/8/comments","events_url":"https://api.github.com/repos/percolatestudio/meteor-factory/issues/8/events","html_url":"https://github.com/percolatestudio/meteor-factory/issues/8","id":92179271,"number":8,"title":"Hard to deal with repeated objects","user":{"login":"mlanett","id":169624,"avatar_url":"https://avatars.githubusercontent.com/u/169624?v=3","gravatar_id":"","url":"https://api.github.com/users/mlanett","html_url":"https://github.com/mlanett","followers_url":"https://api.github.com/users/mlanett/followers","following_url":"https://api.github.com/users/mlanett/following{/other_user}","gists_url":"https://api.github.com/users/mlanett/gists{/gist_id}","starred_url":"https://api.github.com/users/mlanett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlanett/subscriptions","organizations_url":"https://api.github.com/users/mlanett/orgs","repos_url":"https://api.github.com/users/mlanett/repos","events_url":"https://api.github.com/users/mlanett/events{/privacy}","received_events_url":"https://api.github.com/users/mlanett/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-30T19:28:33Z","updated_at":"2015-06-30T20:58:39Z","closed_at":null,"body":"I'm having some problems with objects when the relations form a graph.\r\n\r\nConsider this:\r\n```\r\nFactory.define \"author\", Author, { name: \"F. Scott Fitzgerald\" }\r\nFactory.define \"book\", Book, { title: \"The Great Gatsby\": author: Factory.get(\"author\") }\r\nFactory.define \"contract\", Contract, { author: Factory.get(\"author\"), book: Factory.get(\"book\") }\r\n```\r\n\r\nWhen we Factory.create(\"contract\"), we fail because there will be two inserts of author; one by contract and one when it creates the relation for book. We should only have one author object and the same id in both places. This can be fixed by after() hooks but it's a mess.\r\n\r\nBut, for this following case we might expect that a relation is different each time.\r\n\r\n```\r\nFactory.define \"person\", Person, { name: Random.string }\r\nFactory.define \"dance\", Pair, { leader: Factory.get(\"person\"), follower: Factory.get(\"person\") }\r\n```\r\n\r\nIt's easy to fix the first case by putting a name:object cache in Factory.build and using it to ensure that relations created unique objects. But that would break the latter case. Is the latter case a reasonable expectation? If not then I can probably build the cache and make a PR. If so then we need to figure out the best way to accommodate it."},"comment":{"url":"https://api.github.com/repos/percolatestudio/meteor-factory/issues/comments/117340250","html_url":"https://github.com/percolatestudio/meteor-factory/issues/8#issuecomment-117340250","issue_url":"https://api.github.com/repos/percolatestudio/meteor-factory/issues/8","id":117340250,"user":{"login":"mlanett","id":169624,"avatar_url":"https://avatars.githubusercontent.com/u/169624?v=3","gravatar_id":"","url":"https://api.github.com/users/mlanett","html_url":"https://github.com/mlanett","followers_url":"https://api.github.com/users/mlanett/followers","following_url":"https://api.github.com/users/mlanett/following{/other_user}","gists_url":"https://api.github.com/users/mlanett/gists{/gist_id}","starred_url":"https://api.github.com/users/mlanett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlanett/subscriptions","organizations_url":"https://api.github.com/users/mlanett/orgs","repos_url":"https://api.github.com/users/mlanett/repos","events_url":"https://api.github.com/users/mlanett/events{/privacy}","received_events_url":"https://api.github.com/users/mlanett/received_events","type":"User","site_admin":false},"created_at":"2015-06-30T20:58:39Z","updated_at":"2015-06-30T20:58:39Z","body":"Also one may have a graph after calling multiple create methods, so exposing the cache optionally may also make sense."}}