jrf0110/dirac — pull request #40 by jrf0110 (2014-06-07 17:02:17+00:00)
Title: Relationships Middleware

```javascript
var dirac = require('dirac');

// Make sure to call relationships before registering tables
dirac.use( dirac.relationships() );
dirac.use( dirac.dir( __dirname + '/tables' ) );

dirac.init( config );

// Embed Order Items as an array on the order
// Embed user and restaurant as json objects
var options = {
many: [{ table: 'order_items', alias: 'items' }]
, one: [
{ table: 'restaurants', alias: 'restaurant' }
, { table: 'users', alias: 'user' }
]
};

dirac.dals.orders.findOne( user.id, options, function( error, user ){
// Array.isArray( order.items ) => true
// typeof order.restaurant === 'object' => true
// typeof order.user === 'object' => true
});
```