C2FO/patio — pull request #55 by mbenedettini (2012-11-07 17:54:14+00:00)
Title: Many to one null parent

Hi Doug:

I ran into this bug several weeks ago but it wasn't until now that I had time to properly fix it.

Here's the thing: right after saving a many-to-one children with a null parent (i.e. without parent), the property which exposes the parent returns a Promise instead of what I expected: ```null```.
Accessing the parent property a second time returns null as the Promise has been resolved.

The workaround I've been using is to issue a ```reload()``` which leaves the model instance in the desired state. Sometimes a ```reload()``` was not suitable so I had to check the property with ```isPromiseLike()``` so that my code won't break.

The solution I propose here is what I think is the most homogeneous, taking into account a similar ```_postSave()``` hook in the oneToMany association. And the fix in ```_Association._setAssociationKeys()``` addresses the problem of returning undefined (instead of null) for the association key, which would make ```_checkAssociationKey()``` fail.
It's a simple fix, just a few lines, but, at least for me, fixes a big problem.

Hope you find it useful.
Mariano.

PS: I'm also planning to write a small article about proper unit testing with patio, I'll let you know when it's ready.