{"action":"reopened","issue":{"url":"https://api.github.com/repos/danielspaniel/ember-data-factory-guy/issues/57","labels_url":"https://api.github.com/repos/danielspaniel/ember-data-factory-guy/issues/57/labels{/name}","comments_url":"https://api.github.com/repos/danielspaniel/ember-data-factory-guy/issues/57/comments","events_url":"https://api.github.com/repos/danielspaniel/ember-data-factory-guy/issues/57/events","html_url":"https://github.com/danielspaniel/ember-data-factory-guy/issues/57","id":54902869,"number":57,"title":"Dealing with multiple-inverse associations","user":{"login":"grantovich","id":394835,"avatar_url":"https://avatars.githubusercontent.com/u/394835?v=3","gravatar_id":"","url":"https://api.github.com/users/grantovich","html_url":"https://github.com/grantovich","followers_url":"https://api.github.com/users/grantovich/followers","following_url":"https://api.github.com/users/grantovich/following{/other_user}","gists_url":"https://api.github.com/users/grantovich/gists{/gist_id}","starred_url":"https://api.github.com/users/grantovich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grantovich/subscriptions","organizations_url":"https://api.github.com/users/grantovich/orgs","repos_url":"https://api.github.com/users/grantovich/repos","events_url":"https://api.github.com/users/grantovich/events{/privacy}","received_events_url":"https://api.github.com/users/grantovich/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-01-20T16:16:00Z","updated_at":"2015-04-27T18:57:06Z","closed_at":null,"body":"Consider the following data model:\r\n\r\n```coffee\r\nLocation = DS.Model.extend\r\n  name: DS.attr 'string'\r\n  currentFloorplan: DS.belongsTo 'floorplan', async: true\r\n  upcomingFloorplans: DS.hasMany 'floorplan', async: true\r\n\r\nFloorplan = DS.Model.extend\r\n  name: DS.attr 'string'\r\n  location: DS.belongsTo 'location', async: true, inverse: null\r\n```\r\n\r\nA `Floorplan` always belongs to a `Location`, but the inverse association could be one of two different options, so we set it to `null` because Ember only allows a single inverse. Unfortunately there's no clean way to deal with this situation in Factory Guy, so we end up doing this `Em.run` workaround in every test that involves floorplans:\r\n\r\n```coffee\r\ndescribe 'An association with multiple possible inverses', ->\r\n  it 'requires a clunky workaround', ->\r\n    location = factories.make 'location'\r\n    floorplan = factories.make 'floorplan', location: location\r\n    Em.run -> location.get('upcomingFloorplans').addObject(floorplan)\r\n\r\n    expect(location.get('upcomingFloorplans.length')).to.equal 1\r\n```\r\n\r\nIn Factory *Girl*, this kind of thing is usually handled with [callbacks](https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#callbacks) that access [transient attributes](https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#transient-attributes) to execute some custom behavior. It would of course be a substantial effort to add these features to Factory Guy, so maybe there is an easier targeted solution."}}