Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for polymorphic schema #8

Open
cyppan opened this issue Aug 11, 2016 · 0 comments
Open

Support for polymorphic schema #8

cyppan opened this issue Aug 11, 2016 · 0 comments

Comments

@cyppan
Copy link
Owner

cyppan commented Aug 11, 2016

I see two use cases:

Polymorphic joins

You may want fields in your resources where you could embed different types of resources ordered.
e.g:

(def Links ...)
(def Images ...)
(def Articles
  {:schema
    {:name Str
     :attachments [(PolymorphicResourceField [:links :images])]})

Article data in the DB would look like

{:name "coucou"
 :attachments [{:_type "images" :_id "..."} {:_type "links" :_id "..."}]}

And with links joined on fetch

GET /articles?query={ "relations": { "attachments": {} } }
{
  :_items: [{
    :name "coucou"
    :attachments [ { :_id "..." :_type "images" :url ".../img.jpg" :width 900 :height 500 }
                   { :_id "..." :_type "links" :url "...other-article.html" } ]}]}

Polymorphic document parts

Suppose you have a media field that could be of type "image", or "video", or even "html", each of this type can have different field names, types and validations. It would be nice to have a single media entry with different schemas enabled depending on the "type" discriminant.
e.g:

(def Articles
  {:schema
    {:name Str
     :media (cond
              #(= (:type %) "image")
              {:type (Enum "image") :width Int height Int :url UrlField}
              #(= (:type %) "html")
              {:type (Enum "html") :url UrlField (? :encoding) Str})}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant