Shopify/batman — Issue #229: Add inverseOf option for associations
Author: sidonath
Created: 2011-11-11 18:30:47+00:00
State: open

When writing an application with a slightly more complex data model it would be more efficient to preload an associated record's back-link with self.

Given:
```coffeescript
class Product extends Batman.Model
@hasOne 'product_image', autoload: true, inverseOf: 'product'

class ProductImage extends Batman.Model
@belongsTo 'product', inverseOf: 'product_image'
```
Following should hold:

```coffeescript
p = Product.find id
p.hashKey == p.get('image.product').hashKey
```

Obviously, the feature is inspired by Rails. Mentioning it because a problematic case of hasMany being inverse to belongsTo is ignored in Rails by design.

Thoughts?