 
 mixins = ->
   _.each tables, (opts, name) ->
+    debug "mixing model #{name}"
     if opts.paranoid
       (opts.routes ?= []).push 'get  /:id/restore one:show': (req, res) -> res.render "#{res.locals.route}/delete", item: req.item
       opts.routes.push         'post /:id/restore one:show': (req, res) -> req.item.restore().then (item) -> res.redirect "/#{res.locals.route}/#{item.id}"


define = ->
  _.each tables, (options, tableName) ->
    attributes = configureAttrs(options)
    orm.define tableName, attributes, options

hooks = ->
  _.each orm.models, (model, name) ->
    # defined hooks
    if model.options.hooks_def?.length
      _.each model.options.hooks_def, (hook) ->

relate = ->
  _.each orm.models, (model, name) ->
    return if !(relations = model.options.related)
    debug "relating model #{name}"
    # console.log 'model', name, relations, model.options.include
    _.each relations, (def) -> _.each def, (relation, table) ->
      return console.log "error relating ro table #{table}" if !(foreign = orm.models[table])
