                                            (explode-associated-items attr (item (:name attr)))))))))]
     exploded-item))
 
-(defn extract-attribute [attr input]
-  (println "Attribute: " attr)
-  (println "Input: " input)
-  {attr (input attr)})
+(defn extract-attribute [attr-key input]
+  (let [attr-name (name attr-key)
+        attr-value (input attr-name)]
+  {attr-key attr-value}))
 
 (defn extract-nested-item [attr input]
   (let [association-name   (:name   attr)
         association-schema (:schema attr)
         nested-item (->> association-schema
                          (reduce
-                           (fn [nested-item attr]
-                             (let [attr-name (name attr)
-                                   exploded-attr-name (str association-name "_" attr-name)]
-                               { (keyword attr-name) (input exploded-attr-name) }))
+                           (fn [nested-item nested-attr]
+                             (let [nested-attr-name (name nested-attr)
+                                   exploded-attr-name (str (name association-name) "_" nested-attr-name)]
+                               (conj nested-item { nested-attr (input exploded-attr-name)})))
                            {}))]
     {association-name nested-item}))
 
+(defn extract-associated-item [association-name association-schema input index]
+  (->> association-schema
+    (reduce
+      (fn [associated-item associated-item-attr]
+        (let [associated-item-attr-name (name associated-item-attr)
+              exploded-attr-name (str (name association-name) "_" index "_" associated-item-attr-name)]
+          (conj associated-item { associated-item-attr (input exploded-attr-name)})))
+      {})))
+
 (defn extract-associated-items [attr input]
-  {})
+  (let [association-name   (:name attr)
+        association-schema (:schema attr)
+        attribute-names    (doall (keys input))
+        items-id-pattern   (re-pattern (str (name association-name) "_(\\d+)_"))
+        items-ids (reduce conj #{} (->> attribute-names
+                                        (map #(when-some [x (re-find items-id-pattern %)] (last x)))
+                                        (filter #(not (nil? %)))))
+        associated-items (map #(extract-associated-item association-name association-schema input %) items-ids) ]
+    {association-name associated-items}))
 
 (defn parse-by-schema [input schema]
   (->> schema
        (reduce
          (fn [item attr]
-           (let [t (attribute-type attr)]
-             (case t
-               :attribute               (extract-attribute attr input)
-               :nested-item             (extract-nested-item attr input)
-               :associated-item         (extract-associated-items attr input))))
+           (let [t (attribute-type attr)
+                 imploded-attribute (case t
+                   :attribute               (extract-attribute attr input)
+                   :nested-item             (extract-nested-item attr input)
+                   :associated-items        (extract-associated-items attr input))]
+             (conj item imploded-attribute)))
          {})))
 
 (defn index-malformed? [ctx]


(defn resource-put! [store ctx]
  (db/with-session [session (:hecuba-session store)]
    (let [{request :request} ctx]
      (if-let [item (::item ctx)]
        (let [body       (decode-body request)
              entity_id  (-> item :entity_id)
              username   (sec/session-username (-> ctx :request :session))
              user_id    (:id (users/get-by-username session username))
              profile_id (-> item :profile-id)]
          (db/execute session (hayt/insert :profiles (hayt/values (-> body
                                                                      (assoc :id profile_id)
                                                                      (assoc :user_id user_id)
                                                                      ;; TODO: add storeys, walls, etc.
                                                                      stringify-values)))))
        (ring-response {:status 404 :body "Please provide valid entity_id and timestamp"})))))

(defn resource-handle-ok [store ctx]

        entity_id (:entity_id route-params)]
    (case request-method
      :post (let [decoded-body  (decode-body request)
                  body     (if (= "text/csv" (:content-type request))
                             (let [body-map (reduce conj {} decoded-body)]
                               (parse-by-schema body-map profile-schema))
                             decoded-body)]
              ;; We need to assert a few things
              (if (not= (:entity_id body) entity_id)
                true                  ; it's malformed, game over
