emberjs/data — pull request #1109 by rzurad (2013-08-07 00:03:23+00:00)
Title: Allowing inverse relationships to be nullable.

Greetings,

I ran into a case where Model A has two relationships defined on it - a belongsTo and a hasMany - each of which lead to a type of Model B. Model B has a single hasMany relationship defined on it whose inverse is the hasMany property of Model A, thus:

Model A is in a many-to-many relationship with Model B *and* Model A is in a one-to-none relationship with Model B that is unrelated to the former many-to-many relationship.

The problem happens when you change the value of the one-to-none property: The current logic checks for a truthy `inverse` property defined on the belongsTo relationship. When it doesn't find one, it simply tries to find one for me, so it looks at Model B, sees the hasMany relationship back to Model A, and incorrectly decides that this must be the relationship I'm talking about (interesting that it doesn't seem to check the found inverse property's `inverse` to see if it isn't already explicitly defined to be the inverse of a relationship that is not the current one in question).

Included is a one-line fix inside the `inverseFor` function that looks for explicit nulls on the inverse. Also included is a test case that will fail on emberjs/data:master because it will incorrectly identify an inverse relationship to the `lastParticipant` belongsTo property.

Hopefully this is helpful to some folks.