Created
December 20, 2021 12:55
-
-
Save viebel/a56c879fb73c2afce0e466c43dc6a837 to your computer and use it in GitHub Desktop.
Implementing associations (a la ActiveRecord) in Data-Oriented Programming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; https://guides.rubyonrails.org/association_basics.html | |
(def book-info {:title "Seven Habits of Highly Effective People"}) | |
(def author {:name "Stephen Covey" | |
:id "steph"}) | |
(def association {:association-field :author-id | |
:parent-field :id}) | |
(defn add-to [parent child association] | |
(assoc child | |
(:association-field association) | |
(get parent (:parent-field association)))) | |
(add-to author book-info association) | |
;; {:title "Seven Habits of Highly Effective People" | |
;; :author-id "steph"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment