 
   add_apis_to options.has_many, options.api if options.has_many?
 
-  # Enhance data!
+  # Provide the constructor function for the model object.
+  # Enriches the optionally provided object with model functions.
+  #
+  # @param [Object] self prepopulated data object
+  #
   model = (self = {}) ->
+    # Return api object
+    #
     self.api = -> mapi
+    # Provide all required relationship fields
+    # externalkey (modelname_id), modelplural for API, modelname, modelfunction
+    #
     self.relationship_fields = (name, model) -> [name + '_id', name + 's', name, window[model]]
 
+    # Check if de/encryption functions should be included
+    #
+    if options.encrypted_container?
+      Encryptable self, options.encrypted_container
+
+    # Include sortable functions
     if options.sortable? && options.sortable == true
       Sortable self
+    
+    # Include selectable functions
     if options.selectable? && options.selectable == true
       Selectable self
     
     # Set relations
-    # Lonely
+    # API wise has_one and belongs_to are the same, so we merge them
+    #
     if options.belongs_to?
       unless options.has_one?
         options.has_one = []
       options.has_one = Ham.merge options.belongs_to, options.has_one
 
+    # Single relations
+    # Generated methods:
+    #
+    # @method #relationname_get(params, callbackOrObservable)
+    #   Get relation data from given model
+    # @method #relationname()
+    #   The observable, which is also a lazy get function
+    #   if there's no predefined content in the given object
+    #
     if options.has_one?
       for name, data of options.has_one
         Ham.merge data,
           model: name.capitalize()
 
+        relation_params = self.relationship_fields name, data.model
+        relation_params.push options
+
         fn = window[data.model]
+        
+        ###if typeof self[name + '_id'] != 'function'
+          unless options.editable?
+            options.editable = []
+
+          #options.editable.push name + '_id'
+        ###
+
         if self[name]?
           Observable self, name, new fn(self[name])
         else
           LazyObservable self, name, lazy_single_get_fn, self.relationship_fields(name, data.model)
 
-    # Harem relations
+        self[name + '_get'] = single_get_fn.apply self, relation_params
+
+    # Multiple relations
+    # Generated methods:
+    #
+    # @method #relationnames()
+    #   ObservableArray containing all relation data.
+    #   Is also a lazy get function if there's no predefined
+    #   content in the given object
+    # @method #relationname_get(params, callbackOrObservable)
+    #   Get relation data
+    # @method #relationname_add(params, callback)
+    #   Add new model instance to relationship
+    # @method #relationname_update(id, params, callback)
+    #   Update model instance
+    # @method #relationname_destroy(id, callback)
+    #   Delete model instance
+    #
     if options.has_many?
       for name, data of options.has_many
         Ham.merge data,

    else
      mapi.read(params).done callback

  model.getOne = (observable, id) ->
    model.get observable, { id: id }

  model.create = (params = {}, callbackOrObservable) ->
    callback = (data) ->
      callbackOrObservable.push model(data)
    
    if typeof callbackOrObservable['push'] == 'undefined'
      if typeof callbackOrObservable != 'function'
        console.log 'Collection.find 2nd parameter needs to be either a function or a pushable object (Array, ObservableArray).\nGiven:'
        console.log callbackOrObservable

      callback = callbackOrObservable

    if params.length > 0 || typeof params == 'object'
      mapi.create(params).done callback
    else
      mapi.create().done callback

  return model

ko.bindingHandlers.sortable.afterMove = (element) ->
  if element.item.move_ui?
    element.item.move_ui element

#module.exports = Modelize
'use strict'

# The modelize main function
# Returns a modelize object
#
# @param [Object] options The main configuration object for modelize
#
Modelize = (options) ->
  api.add options.api unless api[options.api]?
  mapi = api[options.api]
